想删除一行记录,怎么得到这一行在数据库中的主键值?数据库主键使用UniqueIdentifier型。
解决方案 »
- 急救!如何单独定义DataSet中第一行的样式?
- 急问:装了SqlServer2005,又卸载,原来的Sql Server2000不能用了
- 多Sheel导出Excel问题好几天都没有解决请大家帮帮忙
- 我想用asp.net里的tale显示数据库里的数据
- 大家帮我看看我的代码还需要改进的地方!!
- 怎么解压缩???
- 用户控件中的属性与方法在.net工具中可以实现智能感知吗?
- asp.net 能否在linux 下运行
- .net平台是用什么语言开发的?
- Help Me!
- 神呀,救救我吧!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- 脚本可以写在page_load里吗?(不考虑服务器)
字段值=datagrid.DataKeys(e.Item.ItemIndex)
runat="server" Width="344px" Height="264px" AutoGenerateColumns="False" DataKeyField="dept_id">后台:
private void DataGrid1_DeleteCommand(object source, System.Web.UI.WebControls.DataGridCommandEventArgs e)
{
string deletecmd="delete from 部门表 where dept_id=@dept_id";
SqlConnection myConnection =new SqlConnection(ConfigurationSettings.AppSettings["sqlconn"] ) ;
SqlCommand myCommand=new SqlCommand(deletecmd,myConnection);
myCommand.Parameters.Add(new SqlParameter("@dept_id",SqlDbType.VarChar ,50));
myCommand.Parameters["@dept_id"].Value=DataGrid1.DataKeys[e.Item.ItemIndex];
myConnection.Open();
myCommand.ExecuteNonQuery();
MyDataBind();
}
你将该主键字段也绑定到表格中,比如所是第0列
如果你不想显示它,可以在属性生成器里设定”可见“为false
strTemp = this.GridList.Items[intIndex].Cells[0].Text;
intKey = Convert.ToInt32(strTemp);
错误:
行 85: myCommand.Parameters["@NEWS_ID"].Value=DataGrid1.DataKeys[e.Item.ItemIndex];
行 86: connection.Open();
行 87: myCommand.ExecuteNonQuery();
行 88: myCommand.Connection.Close();
行 89:
源文件: e:\temp\webapplication4\webform1.aspx.cs 行: 87