SqlDataAdapter ad
=
new
SqlDataAdapter(
"
select top 1 * from users where 1<>1
"
, sqlconn);
//
取个结构
DataTable dt
=
new
DataTable(); SqlCommandBuilder cmb
=
new
SqlCommandBuilder(ad);
//
这一句很关键,必不可少。
ad.Fill(dt);
int
i;
for
(i
=
1
; i
<
10
; i
++
) { DataRow dr
=
dt.NewRow(); dr[
"
uid
"
]
=
"
nid
"
+
i.ToString(); dt.Rows.Add(dr); } ad.Update(dt);
using
System;
using
System.Collections.Generic;
using
System.Text;
using
System.Data.SqlClient;
using
System.Data;
namespace
InsertData {
class
Program {
static
void
Main(
string
[] args) {
string
sqlconn
=
"
server=127.0.0.1;user id=sa;password=xxx;database=test;
"
; SqlDataAdapter ad
=
new
SqlDataAdapter(
"
select top 1 * from test where 1<>1
"
, sqlconn);
//
取个结构
DataTable dt
=
new
DataTable(); SqlCommandBuilder cmb
=
new
SqlCommandBuilder(ad);
//
这一句很关键,必不可少。
ad.Fill(dt);
for
(
int
i
=
1
; i
<
10
; i
++
) { DataRow dr
=
dt.NewRow(); dr[
"
id
"
]
=
i; dt.Rows.Add(dr); } ad.Update(dt); Console.WriteLine(
"
OK
"
); Console.Read(); } } }
SqlConnection conn
=
new
SqlConnection(str); conn.Open(); SqlDataAdapter da
=
new
SqlDataAdapter(
"
select top 1 * from wind where 1<>1
"
, conn); DataTable dt
=
xls_to_dtab(FileUpload1.PostedFile.FileName).Tables[
0
]; DataTable dtt
=
new
DataTable(); da.Fill(dtt); SqlCommandBuilder cmd
=
new
SqlCommandBuilder(da); da.Fill(dt);
for
(
int
i
=
1
; i
<
dt.Rows.Count; i
++
) { dtt.Rows.Add(dt.Rows[i].ToString()); } da.Update(dtt);