Yogesh

Yogesh

  • NA
  • 1
  • 0

Multiple inserts using Data View and commit once with update command

Mar 31 2006 2:59 AM
HI,
I am inserting a number of rows into a table using Data View Object and addnew and endedit methods of dataview. In between addnew and endedit methods, I am supplying values of parameters of insertcommand of data adapter object. The above process is in a loop.
After the loop I am opening Sql connection. Giving Update command of data adapter and closing the connection. But I get all alike multiple rows in database(i.e, last iteration parameter values only) There are no primary key constraints in table.

But If i open sql connection and give update command of data adapter after each iteration, then I get correct row values inserted into the table. But this is against the spirit of dotnet technology.
Please tell What am I missing to get correct results in first approach.

A brief code snippet:

drData = dvTestData.Table.NewRow();

drData["TestID"] = intMaxID;  // these values change in each iteration

drData["TestName"] = strTest;  // these values change in each iteration

drData["Category"] = strCategory;   // these values change in each iteration

daTestData.InsertCommand.Parameters["@TestID"].Value = intMaxID ;

daTestData.InsertCommand.Parameters["@TestName"].Value = strTest;

daTestData.InsertCommand.Parameters["@Category"].Value=strCategory;

dvTestData.Table.Rows.Add(drData);





Thanks.
Y Gupta