lundi 25 novembre 2019

update columns and multiple updates by checkBox the columes

This feels like it shouldn't be an easy one. How do I update my sql server table by checkBox with the columns name ;

DROP TABLE #indebtedness
CREATE TABLE [dbo].[indebtedness](
[Subscriber_No] [bigint] NULL,
[Subscriber_Name] [nvarchar](max) NULL,
[Last_Deact_Date] [date] NULL,
[allocated] [decimal](18, 3) NULL,
[collected] [numeric](18, 3) NOT NULL,
[ID_No] [bigint] NULL,

I'm using desktop application with c# code I look for have to checkBox to update the column from dataGridView

i use something like this code to update my database

 int countSuccess = 0;
            for (int i = 0; i < dataGridView1.Rows.Count - 1; i++)
            {
                // INSERT command:
                using (SqlCommand com = new SqlCommand("UPDATE indebtedness SET autodialtype=@autodialtype,autodial=@autodial,autodate=@autodate,lastdate=@lastdate,lastcall_case=@lastcall_case WHERE  Subscriber_No=@Subscriber_No and company_name=@company_name and indebtedness_name=@indebtedness_name", con))
                {

                    com.Parameters.AddWithValue("@company_name", company_name.Text);
                    com.Parameters.AddWithValue("@indebtedness_name", indebtedness_name.Text);
                    com.Parameters.AddWithValue("@Subscriber_No", dataGridView1.Rows[i].Cells[0].Value);
                    com.Parameters.AddWithValue("@autodialtype", dataGridView1.Rows[i].Cells[1].Value);
                    com.Parameters.AddWithValue("@autodial", "Called");
                    com.Parameters.AddWithValue("@autodate", DateTime.Today.ToShortDateString());
                    com.Parameters.AddWithValue("@lastcall_case", "AutoDial");
                    com.Parameters.AddWithValue("@lastdate", DateTime.Today.ToShortDateString());


                    int numUpd = com.ExecuteNonQuery();

                    countSuccess += numUpd;


                    //com.ExecuteNonQuery();
                }

            }

            MessageBox.Show($"Successfully UPDATED {countSuccess} of {dataGridView1.Rows.Count} rows");

from loke like

I just want to update the column that I check for update only




Aucun commentaire:

Enregistrer un commentaire