Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/database/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# DatagridView迭代跳过值_C#_Database_Foreach_Datagridview_Iteration - Fatal编程技术网

C# DatagridView迭代跳过值

C# DatagridView迭代跳过值,c#,database,foreach,datagridview,iteration,C#,Database,Foreach,Datagridview,Iteration,我有一个datagridview,我想发送到SQL数据库,当我检查数据库中的数据时,它们是不完整的,并且具有空值​​正如你在图片中看到的那样,我做错了什么 if (CB_Cat.Text.Length != 0) { string ligacaoExportDB = "Server=DESKTOP-646CUND\\SQLEXPRESS;Database=DBExportar;Integrated Security=SSPI;";

我有一个datagridview,我想发送到SQL数据库,当我检查数据库中的数据时,它们是不完整的,并且具有空值​​正如你在图片中看到的那样,我做错了什么

if (CB_Cat.Text.Length != 0)
        {
            string ligacaoExportDB = "Server=DESKTOP-646CUND\\SQLEXPRESS;Database=DBExportar;Integrated Security=SSPI;";
            string StrQuery;
            using (SqlConnection conn = new SqlConnection(ligacaoExportDB))
            {
                using (SqlCommand comm = new SqlCommand())
                {
                    comm.Connection = conn;
                    conn.Open();
                    MessageBox.Show(DVSelecao.Rows.Count.ToString());
                    foreach (DataGridViewRow dr in DVSelecao.Rows)
                    {
                        StrQuery = @"INSERT INTO Exportar VALUES ('"
                 /*SKU*/                     + dr.Cells["Ref"].Value + "',' "
                /*EAN*/                      + dr.Cells["EAN"].Value + "',' "
                /*Marca*/                    + dr.Cells["Marca"].Value + "',' "
                /*Categoria1*/               + CB_Cat.Text + "',' "
                /*Categoria2*/               + CB_CAT2.Text + "',' "
                /*Categoria3*/               + "NULL" + "',' "
                /*Categoria4*/               + "NULL" + "',' "
                /*Categoria5*/               + "NULL" + "',' "
                /*Nome*/                     + dr.Cells["Designação"].Value + "',' "
                /*Descricao*/                + dr.Cells["Descricao"].Value + "',' "
                /*Preço*/                    + dr.Cells["PrecoFinal"].Value + "',' "
                /*Promocao*/                 + "N" + "',' "
                /*IniPromo*/                 + "NULL" + "',' "
                /*FimPromo*/                 + "NULL" + "',' "
                /*Destaque*/                 + "N" + "',' "
                /*Disponibilidade*/          + dr.Cells["Stock"].Value + "',' "
                /*Estado*/                   + "Ativo" + "',' "
                /*Imagem*/                   + dr.Cells["URLImg"].Value + "');";
                        // label6.Text = StrQuery;
                        //MessageBox.Show(StrQuery);
                       // DVSelecao.Rows[i].Selected = true;
                        //Debug.WriteLine(i.ToString());
                        Debug.WriteLine(StrQuery);
                        comm.CommandText = StrQuery;
                        comm.ExecuteNonQuery();
                    }
                }
            }

没有理由迭代DGV行来执行任何DB操作-如果使用得当,DBProvider工具会为您解决所有这些问题。数据的存储顺序在关系数据库中通常是未定义的,因为它无关紧要。