110,534
社区成员
发帖
与我相关
我的任务
分享
<x:LinkButtonField ColumnID="deleteField" TextAlign="Center" Icon="Delete" ToolTip="删除" ConfirmText="确定删除此记录?"
ConfirmTarget="Top" CommandName="Delete" Width="50px" />
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
int id = Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]);
if (e.CommandName == "Delete")
{
try
{
/* 这里删除时,一并删除明细表的内容 */
DataSet ds1;
//TSM.Model.CK_AllocInDet modelCK_AllocInDet = m_bllCK_AllocInDet.GetModel(id);
//string searchText = modelCK_AllocInDet.CK_AllocInID.ToString();
string strWhere = "CK_AllocInID = " + id;
ds1 = m_bllCK_AllocInDet.GetList(strWhere);
ds1.Tables[0].Clear();
m_bllCK_AllocIn.Delete(id);
BindGrid();
}
DataSet ds1;
string strWhere = "CK_AllocInID = " + id;
ds1 = m_bllCK_AllocInDet.GetList(strWhere);
int cnt = ds1.Tables[0].Rows.Count;
for (int i = 0; i < cnt; i++)
{
DataRow deleteRow = ds1.Tables[0].Rows[i];
deleteRow.Delete();
}
SqlDataAdapter myDA = new SqlDataAdapter();
try
{
myDA.Update(ds1.Tables[0]);
}
catch (Exception ex)
{
this.Response.Write(ex.Message);
}
/* 这里删除时,先删除从表AllocInDet明细表的内容 */
DataSet ds1;
string strWhere = "CK_AllocInID = " + id;
ds1 = m_bllCK_AllocInDet.GetList(strWhere);
int cnt = ds1.Tables[0].Rows.Count;
SqlDataAdapter myDA = new SqlDataAdapter();
/*
for (int i = 0; i < cnt; i++)
{ // 想逐行删除,又不知怎么从ds中获取每行的主键
ds1.Tables[0].Rows[i].
}
*/
try
{
myDA.Update(ds1.Tables[0]);
}
catch (Exception ex)
{
this.Response.Write(ex.Message);
}
protected void Grid1_RowCommand(object sender, GridCommandEventArgs e)
{
int id = Convert.ToInt32(Grid1.DataKeys[e.RowIndex][0]);
if (e.CommandName == "Delete")
{
try
{
/* 这里删除时,先删除从表AllocInDet明细表的内容 */
DataSet ds1;
string strWhere = "CK_AllocInID = " + id;
ds1 = m_bllCK_AllocInDet.GetList(strWhere);
ds1.Tables[0].Clear();
最后一行,那样删除表,有没有问题呢???????DataSet ds1;
//TSM.Model.CK_AllocInDet modelCK_AllocInDet = m_bllCK_AllocInDet.GetModel(id);
//string searchText = modelCK_AllocInDet.CK_AllocInID.ToString();
string strWhere = "CK_AllocInID = " + id;
ds1 = m_bllCK_AllocInDet.GetList(strWhere);
ds1.Tables[0].Clear();
m_bllCK_AllocIn.Delete(id);
报错如下,和前次一样,这是完整的错误信息窗口。
System.Data.SqlClient.SqlException: DELETE 语句与 REFERENCE 约束"FK__CK_AllocI__CK_Al__5B0E7E4A"冲突。该冲突发生于数据库"testDP",表"dbo.CK_AllocInDet", column 'CK_AllocInID'。
语句已终止。
在 Maticsoft.DBUtility.DbHelperSQL.ExecuteSql(String SQLString, SqlParameter[] cmdParms) 位置 E:\testDP\DBUtility\DbHelperSQL.cs:行号 568
在 TSM.DAL.CK_AllocIn.Delete(Int32 CK_AllocInID) 位置 E:\testDP\DAL\CK_AllocIn.cs:行号 112
在 TSM.BLL.CK_AllocIn.Delete(Int32 CK_AllocInID) 位置 E:\testDP\BLL\CK_AllocIn.cs:行号 56
在 FineUIDemo.AllocIn.Grid1_RowCommand(Object sender, GridCommandEventArgs e) 位置 E:\testDP\EmptyProjectNet20\CK_AllocIn.aspx.cs:行号 139
恳求各位大侠有以教我,拜谢了。。