Click here to Skip to main content
15,941,071 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I am trying to delete multiple records from WinForms. Created one Delete Stored Procedure which will delete multiple records and after deleting it will reorder index wise like 1,2,3 and so on.

and providing 4 input parameters in SP which come from Application.

In Code
I created one WCF Delete Method with mentioning the SP name along with mentioning 4 parameters which is used in SP .

and the same method I am trying to bind with delete in Client Side.
But while debugging all parameters values are coming null. What and where I need to fix it .Please help me

What I have tried:

1.Parameters in SP
@TBL_ID varchar(2000),
@ACCT_ID int,
@SEQ_NUM Char (4),
@CMNT_TXT varchar (100)

2.WCFMethod mentioned
public void DeleteCollPolicies(string strCollPolicyIds ,int CollAcctID,string Term_Seq_Num, string Iteration_Cmnt_Text)

SqlParameter[] sqlParameter = new SqlParameter[4];

sqlParameter[0] = new SqlParameter("@TBL_ID", SqlDbType.VarChar, 2000, ParameterDirection.Input, true, 0, 0, "TBL_POL_COLL_AGMT_DTLS_ID", DataRowVersion.Current, strCollPolicyIds);
sqlParameter[1] = new SqlParameter("@COLL_ID", SqlDbType.Int, 4, ParameterDirection.Input, true, 10, 0, "COLL_ID", DataRowVersion.Current, CollAcctID);
sqlParameter[2] = new SqlParameter("@SEQ_NUM", SqlDbType.Char, 4, ParameterDirection.Input, true, 10, 0, "SEQ_NUM", DataRowVersion.Current, Term_Seq_Num);
sqlParameter[3] = new SqlParameter("@CMNT_TXT", SqlDbType.VarChar, 100, ParameterDirection.Input, true, 10, 0, "CMNT_TXT ", DataRowVersion.Current, Iteration_Cmnt_Text);
SqlHelper.ExecuteNonQuery(strConnStr, CommandType.StoredProcedure, "DeleteRecords", sqlParameter);

//return listdata;

// return Convert.ToInt32(sqlParameter[4].Value);

3.Finally the Delete method with binding WCF method

private void btnDelete_Click(object sender, EventArgs e)

string strCollPolicyIds = string.Empty;
string Seq_Num = string.Empty;
string Cmnt_Text = string.Empty;
int cctID = ThisWorkbook.AccountId ;

int total = dataGridView1.Rows.Cast<datagridviewrow>().Where(p => Convert.ToBoolean(p.Cells["chkbox"].Value) == true).Count();
if(total > 0)
string message = $"Are you sure want to delete {total} row?";
message = $"Are you sure want to delete {total}rows";
if (MessageBox.Show(message, "Message", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
for(int i = 0; i< dataGridView1.RowCount; i++)
// "1,2,3"
DataGridViewRow row = dataGridView1.Rows[i];
if(Convert.ToBoolean(row.Cells["chkbox"].Value)== true)
ServClient.DeleteCollPolicies(strCollPolicyIds, AcctID, Seq_Num, Cmnt_Text);

Member 15627495 31-May-22 9:41am    
Instead of binding Datas after a delete/update, why don't you make a "select..." again ?
trying to bind datas after update or delete could bring synchronization/mirroring faults.

- select the rows
- delete the rows in db.
- query the Db for new rows collection
- refresh the dataset ( or array/collection of rows )
- clear the datagridview
- populate the datagridview with the new rows collection.

Instead of going easy, you force yourself to write new function but not simple at all.
because of several 'containers' to refresh and read/write.
[no name] 2-Jun-22 12:29pm    
You should get 1 "tier" working at a time. You're trying to fit a multi-tier application into a single function.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900