Click here to Skip to main content
15,742,120 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
hi all

I'm trying to insert multiplte rows from gridviw into database?

like that

for (int i = 0; i < dt.Rows.Count; i++)
                Items it = new Items(dt.Rows[i]["Name"].ToString(), dt.Rows[i]["Code"].ToString());


but it inserts only the first row and ignore the other

what can I do to insert all rows ??
thanx in advance

The problem seems to be that you are really not inserting the new Item anywhere. You are calling the it.insert() but there is nothing in the call for the constructor of new item to indicate that there is somewhere to insert the new object!!

Maybe this is not helpful, but you may have an incomplete explanation of what you are coding.
Share this answer
Hi sara,

I think this is bad practice to insert multiple row into database.

You should try to create XML string and put your logic in Database side stored procedure and insert record.

This will also decrease your round trip for connecting database.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900