TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
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
Reply
Answers (
0
)
Populating a datagrid on a Windows form
Advanced queries on DataSet object...