如何使用存储过程的n层删除windows appli中的gridview数据 [英] how to delete gridview data in windows appli using n-tier with stored procedure
本文介绍了如何使用存储过程的n层删除windows appli中的gridview数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
private void dataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
{
if (e.ColumnIndex < 1)
{
string cid = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
//MessageBox.Show(cid);
DialogResult dr = MessageBox.Show("Are you sure want to delete the record permenantly ?", "Confirm Delete", MessageBoxButtons.YesNo);
if (dr == DialogResult.Yes)
{
obj.DELETE_CUSTOMER(dataGridView1.CurrentRow.Index);
Binddata();
}
}
}
public Database db;
public CustomerDataManagement(string csstring)
{
db = DatabaseFactory.CreateDatabase(csstring);
}
// DELETE CUSTOMER DATA
private const string USP_Delete_Customer_Data = "USP_Delete_Customer_Data";
private const string USP_Delete_Customer_Data_PARAM_1 = "customer_id";
public int DELETE_CUSTOMER(int customer_id)
{
try
{
DbCommand com = db.GetStoredProcCommand(USP_Delete_Customer_Data);
db.AddInParameter(com, USP_Delete_Customer_Data_PARAM_1, DbType.Int32, customer_id);
return db.ExecuteNonQuery(com);
}
catch (Exception)
{
throw;
}
}
存储程序
--------------- --------
STORED PROCEDURE
-----------------------
ALTER PROCEDURE [dbo].[USP_Delete_Customer_Data]
(
@customer_id INT
)
AS
BEGIN
delete FROM tbl_customer_deta WHERE customer_id=@customer_id
end
推荐答案
正如我上次发布的那样:数据库表中没有删除记录 [ ^ ]问题很可能是您的DataGridView行索引与您的数据库ID不匹配。
As I said when you posted this last time: No delete record in the database table[^] The problem is very likely to be that your DataGridView row indexes do not match your database IDs.
这篇关于如何使用存储过程的n层删除windows appli中的gridview数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文