使用C#在Datagridview中检查复选框时如何更新空值

时间:2016-12-27 13:07:23

标签: c# datagridview

我有问题。我想使用OleDB删除Excel数据但是当我在互联网上寻找参考时,很多人说它无法做到。所以在这里我想将在datagridview中检查的数据更改为空值。任何人都可以帮助我吗?

string tampungsementara = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\Proyek Alfon\JadwalPengisianATM\Tampung Data Sementara.xlsx;Extended Properties='Excel 12.0 xml;HDR=YES';";

 private void MoveToScheduleBtn_Click(object sender, EventArgs e)
        {
            BackgroundWorker bw = new BackgroundWorker();
            bw.DoWork += new DoWorkEventHandler(PindahKeJadwalIsiBW_DoWork);
            bw.RunWorkerCompleted += new RunWorkerCompletedEventHandler(PindahKeJadwalIsiBW_RunWorkerCompleted);

            try
            {
                bw.RunWorkerAsync();
                //pw3.ShowDialog();
            }
            catch
            {
                MessageBox.Show("File gagal dipindah !");
            }
        }


 private void PindahKeJadwalIsiBW_DoWork(object sender, DoWorkEventArgs e)
        {
            foreach (DataGridViewRow item in ReviewGV.Rows)
            {
                if (Convert.ToBoolean(item.Cells[0].Value) == true) 
                { 
                    OleDbConnection kon = new OleDbConnection(tampungsementara);
                    OleDbCommand command = kon.CreateCommand();
                    OleDbCommand command2 = kon.CreateCommand();

                    kon.Open();
                    command.CommandText = "INSERT INTO [Schedule$] ([WSID], [Lokasi]) VALUES (wsid, lokasi)";
                    command2.CommandText = "UPDATE [Unschedule$] SET [WSID]= , [Lokasi]= , [Cas A Den 50] = , [Cas B Den 50] = , [Cas C Den 100] = , [Cas D Den 100] = , [Reject] = , [Saldo] =  WHERE [WSID] = '" + item.Cells[1].Value + "'"; // I want to update empty value based on WSID checked in datagridview. It doesn't change anything

                    command.Parameters.AddWithValue("wsid", item.Cells[1].Value);
                    command.Parameters.AddWithValue("lokasi", item.Cells[2].Value);

                    command.ExecuteNonQuery();

                    kon.Close();
                }
            }
        }

0 个答案:

没有答案