Click here to Skip to main content
15,893,487 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
i have a data table input using sql adapater how to insert update delete event in asp.net c#

my code is as follows.


C#
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.
Posted
Comments
Sunasara Imdadhusen 27-Feb-15 4:20am    
Are you getting any error?

Yes im not getting any error but unable to insert into data base..
 
Share this answer
 
Guys please help me .......
unable to update events......
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900