日期:2014-05-19  浏览次数:20946 次

c#.net里怎么一次添加多条数据?
举个例子:
表里的字段为:
userid   username
我把多条记录添加到了DataGrid里了,DataGrid里的内容如下:
userid   username
1001       张三
1002       李四
1003       王五
当我点击一下button按扭的时候,能同时把这三条记录添加到数据库表里,怎么实现?谢谢!

------解决方案--------------------
foreach (GridViewRow gr in GridView1.Rows)
{
if (gr.RowType ==DataControlRowType.DataRow)
{
Label userid= (Label)gr.Cells[0].FindControl( "userid ");
Label username= (Label)gr.Cells[1].FindControl( "username ");
if (userid!= null && username!=null)
{
string id = userid.Text;
string num = username.Text;

写你操作的方法(id,num);
}
}
}