求助。在asp.net中,datagrid空间中·我设置了一个按钮列,按钮类型是linkbutton,操作内容是 修改和取消。
我修改的时候·测试cmd.ExecuteNonQuery()返回影响值是1,为什么数据库里面的数据没变化。这是代码·protectedvoidDataGrid1_Upda...
我修改的时候·测试cmd.ExecuteNonQuery()返回影响值是1,为什么数据库里面的数据没变化。这是代码·
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string[] textbox=new string[2];
int[] text = new int[2];
int introw;
string key = string.Empty;
introw = e.Item.ItemIndex;
textbox[0] = ((TextBox)DataGrid1.Items[introw].Cells[1].Controls[0]).Text.ToString();
text[0] =Convert.ToInt32( ((TextBox)DataGrid1.Items[introw].Cells[2].Controls[0]).Text);
text[1] = Convert.ToInt32(((TextBox)DataGrid1.Items[introw].Cells[3].Controls[0]).Text);
textbox[1] = ((TextBox)DataGrid1.Items[introw].Cells[4].Controls[0]).Text.ToString();
string txtone = textbox[0];
string txttwo = textbox[1];
int intone = text[0];
int inttwo = text[1];
key = (String)DataGrid1.DataKeys[introw];
OleDbConnection con = Connection.createcon();
con.Open();
string sql = "Update Product set Package='" + txtone + "',ProductNumber='" + intone + "',Purchaseprice='" + inttwo + "', Remarks='" + txttwo + "' where ProductID='" + key + "'";
OleDbCommand cmd = new OleDbCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script language='javascript' type='text/javascript'> alert('修改成功');location.href='DeleteorxiugaiMessage.aspx'</script>");
} 展开
protected void DataGrid1_UpdateCommand(object source, DataGridCommandEventArgs e)
{
string[] textbox=new string[2];
int[] text = new int[2];
int introw;
string key = string.Empty;
introw = e.Item.ItemIndex;
textbox[0] = ((TextBox)DataGrid1.Items[introw].Cells[1].Controls[0]).Text.ToString();
text[0] =Convert.ToInt32( ((TextBox)DataGrid1.Items[introw].Cells[2].Controls[0]).Text);
text[1] = Convert.ToInt32(((TextBox)DataGrid1.Items[introw].Cells[3].Controls[0]).Text);
textbox[1] = ((TextBox)DataGrid1.Items[introw].Cells[4].Controls[0]).Text.ToString();
string txtone = textbox[0];
string txttwo = textbox[1];
int intone = text[0];
int inttwo = text[1];
key = (String)DataGrid1.DataKeys[introw];
OleDbConnection con = Connection.createcon();
con.Open();
string sql = "Update Product set Package='" + txtone + "',ProductNumber='" + intone + "',Purchaseprice='" + inttwo + "', Remarks='" + txttwo + "' where ProductID='" + key + "'";
OleDbCommand cmd = new OleDbCommand(sql, con);
cmd.ExecuteNonQuery();
con.Close();
Response.Write("<script language='javascript' type='text/javascript'> alert('修改成功');location.href='DeleteorxiugaiMessage.aspx'</script>");
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询