I have two gridview data to be inserted at a time on one click to two tables in c#

Posted by Rajasekhar0544 under C# on 9/27/2012 | Points: 10 | Views : 1405 | Status : [Member] | Replies : 3
Hi,

I have two datagridviews have information, that info has to be inserted to datatables at one click in windows application.

Thanks&Regards,
Rajsekhar




Responses

Posted by: Sureshknkt7 on: 9/27/2012 [Member] Starter | Points: 25

Up
0
Down
Hi,


the following code will helpful to you but the code not for Windows application,
But the logic is same for windows also,

In a Button Click Event, Write the following Code,


DataTable dt = new DataTable();
for (int j = 0; j < grdList.Rows.Count; j++)
{
DataRow dr;
GridViewRow row = grdList.Rows[j];
dr = dt.NewRow();
for (int i = 0; i < row.Cells.Count; i++)
{
dr[i] = row.Cells[i].Text;
}

dt.Rows.Add(dr);
}


the above code same for another Gridview also and bind it to same datatable

Thank You,
Suresh



Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
fetch the gridview dataset or datatable then using loop and then insert your new dataset or datatable.

Mark as Answer if its helpful to you

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Jayakumars on: 9/27/2012 [Member] [MVP] Bronze | Points: 25

Up
0
Down
hi
Please mark as answer if it helpful to you.

Mark as Answer if its helpful to you

Rajasekhar0544, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response