Tech
Forums
Jobs
Books
Events
Videos
Conference
Annual Conference
Bcrypt
Ai Conference
Live
More
Interviews
Certification
Training
Career
Members
News
Blogs
Contribute
An Article
A Blog
A Video
An Ebook
An Interview Question
Register
Login
0
Answer
Multiple inserts using Data View and commit once with update command
Ask a question
Ask a question
Upload Source Code:
Select only zip and rar file.
Yogesh
18y
1.9k
1
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
Post
Reset
Cancel
Answers (
0
)
Next Recommended Forum
Populating a datagrid on a Windows form
Advanced queries on DataSet object...