批量复制gridview到数据库 [英] bulk copy gridview to database
本文介绍了批量复制gridview到数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
protected void Button2_Click(object sender, EventArgs e)
{
foreach (GridViewRow g1 in GridView1.Rows)
{
string Name = g1.Cells[0].Text;
string job = g1.Cells[1].Text;
SqlCommand com = new SqlCommand("insert into emp(Name,job) values ('" +Name + "','" +job+ "')", con);
con.Open();
com.ExecuteNonQuery();
con.Close();
}
}
先生,当我在数据库中保存值时我得到null值数据库我计算数据库中的插入值
sir when i save the value in database i get null value in database i count insert value in database
推荐答案
这里我附加的代码与你的代码非常相似,但主要的是它在我的应用程序中有效。 br $> b $ b
Here I'm attaching the code which much similar with your code,but main things is that it works in my application.
protected void Button2_Click(object sender, EventArgs e)
{
con.Open();
foreach(System.Data.DataRow D in dt.Rows)
{
DropDownList1.Items.Add(D[0].ToString());
}
foreach (GridViewRow G in GridView1.Rows)
{
string cmdstring = "INSERT INTO TempTable(ID,City) VALUES(" + G.Cells[0].Text + ",'" + G.Cells[1].Text + "')";
System.Data.SqlClient.SqlCommand cmd = new System.Data.SqlClient.SqlCommand(cmdstring, con);
cmd.ExecuteNonQuery();
}
con.Close();
}
检查一下,如果你还没有找到输出,请再次告诉我。
check it if you still not found your output then tell me again.
这篇关于批量复制gridview到数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文