通过将数据插入数据库来解决数据集问题 [英] problem on dataset by inserting data into database
本文介绍了通过将数据插入数据库来解决数据集问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
你好朋友
我创建了数组列表,然后将arraylist存储到数据集中.然后,我需要使用sqlbulkcopy将数据集存储到数据库中.它显示了最佳的重载方法和无效的参数.
我的代码是
hello friends
i created array list and then i stored arraylist into dataset. Then i need to store that dataset into database using sqlbulkcopy. it shows best overload method and invalid argument.
my code is
ArrayList arrayc = new ArrayList();
arrayc.Insert(0, "hi");
arrayc.Insert(1, "asd");
arrayc.Insert(2, "weras");
DataSet ds = new DataSet();
DataTable dt = new DataTable();
ds.Tables.Add(dt);
ds.Tables[0].Columns.Add("name", System.Type.GetType("System.String"));
foreach (string str in arrayc)
{
DataRow row = ds.Tables[0].NewRow();
row[0] = str;
ds.Tables[0].Rows.Add(row);
}
SqlConnection con = new SqlConnection("Data Source=sourceconn;database=dbname;Trusted_Connection=true");
con.Open();
SqlBulkCopy bc = new SqlBulkCopy(con);
bc.BatchSize = 30;
bc.NotifyAfter = 30;
bc.SqlRowsCopied += new SqlRowsCopiedEventHandler(bc_SqlRowsCopied);
bc.DestinationTableName = "ase";
bc.WriteToServer(ds);
请给我打电话解决方案
please tel me the solution
推荐答案
您好,请参考本文以获取 ^ ]
Hi, refer to this article for the correct implementation of Bulk Copy with C#.Net[^]
通过使用以下代码,您可以将数据集插入或更新到数据库,
By using the following Code you can insert or update from dataset to database,
try
{
SqlDataAdapter1.Update(Dataset1.Tables["Table1"]);
}
catch (Exception e)
{
// Error during Update, add code to locate error, reconcile
// and try to update again.
}
这篇关于通过将数据插入数据库来解决数据集问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文