C# datagridview输入数据后,怎样通过保存修改按钮把数据保存到数据库中,要源代码

如题所述

第1个回答  2013-05-26
string a = this.GridView2.DataKeys[e.RowIndex][0].ToString();
string str = ((TextBox)this.GridView2.Rows[e.RowIndex].Cells[0].Controls[0]).Text;
string ds = ((TextBox)this.GridView2.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
SqlConnection con = new SqlConnection("Data Source=.;Initial Catalog=Test;Integrated Security=True");
con.Open();
SqlCommand cmd=new SqlCommand("update T1 set T_title='"+str+"' ,T_date='"+ds+"' where T_id='"+a+"'",con);

if (Convert.ToInt32(cmd.ExecuteNonQuery()) > 0)
{
Response.Write("更新成功");
}
else
Response.Write("更新失败");
bind();
}本回答被网友采纳
第2个回答  2013-05-25
多张表查询绑定的就会保存不了..起码很多人做不到。。。
第3个回答  2013-05-24
不需要代码都可以实现,留联系远程教你。。。
相似回答