我用gridView进行更新时如何都获取不了更改的值 5
publicvoidMyExecute(stringsql){using(SqlConnectionconn=newSqlConnection("DataSource=P...
public void MyExecute(string sql)
{
using (SqlConnection conn = new SqlConnection("Data Source=PC-201010292125;Initial Catalog=Mybook;Integrated Security=True"))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string strname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
string strauto = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim();
string strprice = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim();
string strinfo = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim();
string strsql = string.Format("update bookInfo set bookname='{0}',bookauto='{1}',bookprice='{2}',bookinfo='{3}' where bookid='{4}'", strname, strauto, strprice, strinfo, strid);
MyExecute(strsql);
GridView1.EditIndex = -1;
MyBind();
} 展开
{
using (SqlConnection conn = new SqlConnection("Data Source=PC-201010292125;Initial Catalog=Mybook;Integrated Security=True"))
{
conn.Open();
SqlCommand cmd = new SqlCommand(sql, conn);
cmd.ExecuteNonQuery();
}
}
protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
{
string strid = GridView1.DataKeys[e.RowIndex].Value.ToString();
string strname = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text.Trim();
string strauto = ((TextBox)GridView1.Rows[e.RowIndex].Cells[2].Controls[0]).Text.Trim();
string strprice = ((TextBox)GridView1.Rows[e.RowIndex].Cells[3].Controls[0]).Text.Trim();
string strinfo = ((TextBox)GridView1.Rows[e.RowIndex].Cells[4].Controls[0]).Text.Trim();
string strsql = string.Format("update bookInfo set bookname='{0}',bookauto='{1}',bookprice='{2}',bookinfo='{3}' where bookid='{4}'", strname, strauto, strprice, strinfo, strid);
MyExecute(strsql);
GridView1.EditIndex = -1;
MyBind();
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询