从gridview批量插入数据库 [英] Bulk insert from gridview to database
本文介绍了从gridview批量插入数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个包含100多个记录的gridview,在itemtemplate中,我有用于eah行的ackeckbox.在这里,我想将所有选中的复选框行插入数据库中
i have a gridview that contain more than 100 records, in itemtemplate i have ackeckbox for eah row. Here i want to insert all checked checkbox row to the database
<asp:GridView ID="GridView1" runat="server" Width="96%" PageSize="10" OnSelectedIndexChanging="GridView1_SelectedIndexChanging" OnRowCommand="GridView1_RowCommand" >
<columns>
<asp:TemplateField HeaderText="Select">
<itemtemplate>
<asp:CheckBox ID="chkbox" runat="server">
</itemtemplate>
<asp:TemplateField HeaderText="Remark">
<itemtemplate>
<asp:Label ID="lblremark" runat="server">
</itemtemplate>
</columns>
以上是我拥有的源代码.
背后的代码
the above is the source code i have.
Code behind
protected void btnview_Click(object sender, EventArgs e)
{
GridView1.Visible = true;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=TNVKP_8;Integrated Security=True");
con.Open();
DataSet reportData = new DataSet();
//reportData.ReadXml(Server.MapPath("test.xml"));
filename = System.IO.Path.GetExtension(FileUpload1.FileName.ToString());
if (filename == ".xml")
{
reportData.ReadXml(Server.MapPath(FileUpload1.FileName));
GridView1.DataSource = reportData;
GridView1.DataBind();
con.Close();
}
else
{
GridView1.Visible = false;
Response.Write("Invalid File");
}
}
上面的代码我曾经用来在gridview中查看xml数据,现在我想将gridview数据插入数据库中.为此发布解决方案
在此先感谢
the above code i have used to view the xml data in the gridview now i want to insert the gridview data in to database. Post solution for this
Thanks in advance
推荐答案
您可以在后端代码中进行批量插入.参考: http://msdn.microsoft.com/en-us/library/ms188365.aspx [ ^ ]
You can do the bulk insert in backend code. Reference at: http://msdn.microsoft.com/en-us/library/ms188365.aspx[^]
找到了CP文章
使用不带xxxDataSource(SqlDataSource,ObjectDataSource等)的GridView进行批量编辑 [使用XML一次将多行发送到存储过程中 [ ^ ]
Found a CP article
Bulk Edit with GridView without xxxDataSource (SqlDataSource, ObjectDataSource, etc.)[^]
Using XML To Send Multiple Rows At Once Into A Stored Procedure[^]
这篇关于从gridview批量插入数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文