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"
using (SqlConnection connection = new
SqlConnection(connectionString))
{
SqlDataAdapter adapter = new SqlDataAdapter();
adapter.MissingSchemaAction = MissingSchemaAction.AddWithKey;
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);
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;
int i= adapter.Update(dataTable);
}
Unable to insert update events.