dataset插入資料庫
發布時間: 2025-03-31 12:18:25
㈠ 怎麼入資料庫里插入數據 通過 DataSetMSDataSetGenerator
您好, 這樣的:
jjyyDataSet.ListDataTable ldt = new jjyyDataSet.ListDataTable();//對應資料庫的list jjyyDataSet.ListRow lr= ldt.NewListRow();
lr.key = "test";
lr.Message = "test";
lr.Amount = 123;
lr.Name = "tester";
lr.rDate = DateTime.Now;
ldt.AddListRow(lr);
用自動生成的TableAdapter類里的方法把數據寫入資料庫
jjyyDataSetTableAdapters.ListTableAdapter.Update(ldt);
㈡ c#怎麼將dataset裡面的值放到資料庫
DataSet裡面都是很多個DataTable,DataTable可以用sqlBulkCopy來批量提交,性能極高。可以一次性提交構建好的DataTable表。
using(SqlBulkCopysqlBC=newSqlBulkCopy("資料庫連接字元串"))
{
//設定目標列表
sqlBC.DestinationTableName="T_TableName";
//設定本地列-->目標列的一一對應關系
//目標表中第0列一般為自動增長的ID,因此本地的0通常與資料庫中的第1列對應
sqlBC.ColumnMappings.Add(0,1);
sqlBC.ColumnMappings.Add(1,2);
sqlBC.ColumnMappings.Add(2,3);
sqlBC.ColumnMappings.Add(3,4);
sqlBC.ColumnMappings.Add(4,5);
//批量提交
sqlBC.WriteToServer(dt);
}
㈢ c# valuemember插入數據到資料庫的問題,不能插入對應的數據到資料庫
因你只是將name加進了combobox,所有沒有ID值。
在獲得DATASET後,不要FOREACH子句,直接用下面的代碼
comboBox1.DataSource = ds.Tables[0];
comboBox1.DisplayMember = "departname";
comboBox1.ValueMember = "departid「
熱點內容