C# .NET - Batch insert

Asked By cool mugil on 06-Nov-07 02:04 AM

hai,

i am using the following code to perform batch insert.were i am going wrong.i does not able to insert.


SqlConnection con = new SqlConnection();

SqlCommand sqlcommand = new SqlCommand();

SqlDataAdapter adapt = new SqlDataAdapter(sqlcommand);

con.ConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ToString();

con.Open();

sqlcommand.CommandType = CommandType.StoredProcedure;

sqlcommand.CommandText = "usp_inssample";

sqlcommand.Connection = con;

SqlDataAdapter adap = new SqlDataAdapter();

adap.InsertCommand = sqlcommand;

//loads data from table

objds = objinsert.BindGrid();

// for (int i = 0; i <= objds.Tables[0].Rows.Count - 1; i++)

{

SqlParameter param1 = adap.InsertCommand.Parameters.Add("@proctitle", SqlDbType.VarChar);

param1.SourceColumn = "proctitle";

param1.SourceVersion = DataRowVersion.Original;

param1.Value = "hello";

}

/// Server.Execute("usp_inssample");

adap.Update(objds);


please help me.

thanks in advance

A DataAdapter will only update rows that have changed.

Peter Bromberg replied to cool mugil on 06-Nov-07 06:00 AM
If you actually want to insert this data, you need to do the inserts with a regular SqlCommand object, not a dataadapter. Actually, what you show is somewhat confusing as to what the actual goal is here. Maybe a bit more details about what the end result is expected to be?

Batch update

cool mugil replied to Peter Bromberg on 06-Nov-07 07:02 AM

hai,

      Actually i had some 10000's of data retrieved from one database A that is loaded into a dataset and viewed in grid.When user hit save button i want to insert all 10000's into database b with a single execution,instead of going in for loop.how can i do this.

please give me some suggestions.

thanks in advance

regards

mugil