datagrid的更新问题

benhuang 2009-04-08 12:56:51

protected void orgUpdate(object sender,DataGridCommandEventArgs e)
{
string strorgid = e.Item.Cells[0].Text.Trim();
string strName = ((TextBox)e.Item.Cells[4].Controls[1]).Text.Trim();
string strType = ((TextBox)e.Item.Cells[5].Controls[1]).Text.Trim();
string strDesc = ((TextBox)e.Item.Cells[6].Controls[1]).Text.Trim();

string strSQL = "UPDATE Organization SET orgname='" + strName.Replace("'", "''") + "',orgtype='" + strType.Replace("'", "''") + "',orgdesc='" + strDesc.Replace("'", "''") + "'where orgid='" + strorgid + "'";
string strConn = "server=localhost;uid=sa;pwd=;database=HR";
SqlConnection connUpdate = new SqlConnection(strConn);
SqlCommand sqlCommandUpdate = new SqlCommand(strSQL, connUpdate);
sqlCommandUpdate.Connection.Open();
sqlCommandUpdate.ExecuteNonQuery();
displayMain.EditItemIndex = -1;
sqlCommandUpdate.Connection.Close();


displayMain.EditItemIndex = -1;
displayMain.DataSource = CreateDataView();
displayMain.DataBind();
}

请问这样写哪里有问题了?我更新不了数据库!
...全文
47 1 打赏 收藏 转发到动态 举报
写回复
用AI写文章
1 条回复
切换为时间正序
请发表友善的回复…
发表回复
麻子Mozart 2009-04-08
  • 打赏
  • 举报
回复
帮顶

111,126

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Creator Browser
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧