Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Post
Register
Login
0
Reply
Multiple inserts using Data View and commit once with update command
Yogesh
Mar 31 2006 2:59 AM
1.9k
Reply
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
Upload Source Code
Select only zip and rar file.
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
Populating a datagrid on a Windows form
Advanced queries on DataSet object...