批量插入数据库数据

    static void Main()
{
System.Data.DataTable dt = new System.Data.DataTable("t");
dt.Columns.AddRange(new DataColumn[] {new DataColumn("id"),new DataColumn("name"),new DataColumn("adress")});
for (int i = 0; i < 10; i++)
{
dt.Rows.Add(new object[] { i, "小明", "山上"});

}
foreach (DataRow row in dt.Rows)
{
Console.WriteLine("编号:{0}姓名:{1}地址:{2}", row[0], row[1], row[2]);
}
DataSet dset = new DataSet();
dset.Tables.Add(dt);
SqlConnection con=new SqlConnection(@"Data Source=HJXPC\SQLEXPRESS;Initial Catalog=newscatch;Integrated Security=True");
SqlDataAdapter dap = new SqlDataAdapter("select top 1 * from test", con);
SqlCommandBuilder cmdbulid = new SqlCommandBuilder(dap);
int n= dap.Update(dset, "t");
dset.AcceptChanges();
Console.ReadKey();
}


编辑器加载中...

posted @ 2011-12-06 17:21  Rookier  阅读(292)  评论(0编辑  收藏  举报