本文介绍了数据表插入更新Adonet的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个使用sql adapater的数据表输入如何在asp.net中插入更新删除事件c#
我的代码如下。
i have a data table input using sql adapater how to insert update delete event in asp.net c#
my code is as follows.
public static void BatchUpdate(DataTable dataTable)
{
string connectionString = "My connections string"
//// Assumes GetConnectionString() returns a valid connection string.
// Connect to the AdventureWorks database.
using (SqlConnection connection = new
SqlConnection(connectionString))
{
// Create a SqlDataAdapter.
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
//// Create the commands.
adapter.SelectCommand = new SqlCommand(
"SELECT EmpolyeeKey,EffectiveDate,EmpolyeeAllowanceDeduction FROM [dbo].[EmployeeAllwDedDetail]", connection);
adapter.Fill(dataTable);
adapter.InsertCommand = new SqlCommand(
"INSERT INTO EmployeeAllwDedDetail (EmpolyeeKey, EffectiveDate,EmpolyeeAllowanceDeduction,CreatedDate) " +
"VALUES (@EmpolyeeKey, @EffectiveDate,@EmpolyeeAllowanceDeduction,@CreatedDate)", connection);
adapter.UpdateCommand = new SqlCommand(
"UPDATE Customers SET EmpolyeeAllowanceDeduction = @EmpolyeeAllowanceDeduction, ModifiedDate = @ModifiedDate " +
"WHERE EmpolyeeKey = @EmpolyeeKey", connection);
// Create the parameters.
adapter.InsertCommand.Parameters.Add("@EmpolyeeKey",
SqlDbType.BigInt, 1000, "EmpolyeeKey");
adapter.InsertCommand.Parameters.Add("@EffectiveDate",
SqlDbType.DateTime, 40, "EffectiveDate");
adapter.InsertCommand.Parameters.Add("@EmpolyeeAllowanceDeduction",
SqlDbType.Xml, 100000, "EmpolyeeAllowanceDeduction");
adapter.InsertCommand.Parameters.Add("@EmpolyeeKey",
SqlDbType.DateTime, 40, "EmpolyeeKey");
adapter.UpdateCommand.Parameters.Add("@EmpolyeeAllowanceDeduction",
SqlDbType.VarChar, 40, "EmpolyeeAllowanceDeduction");
adapter.UpdateCommand.Parameters.Add("@ModifiedDate",
SqlDbType.Char, 5, "ModifiedDate").SourceVersion =
DataRowVersion.Original;
// Execute the update.
int i= adapter.Update(dataTable);
}
无法插入更新事件。
Unable to insert update events.
推荐答案
这篇关于数据表插入更新Adonet的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!