Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/298.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获取所有数据并将其插入数据库 string IdDB=“从transtbl中选择transid,其中fullname=”+textBox6.Text+”; con.选择rec(IdDB,dt); 字符串IdDB2=dt.Rows[0].ItemArray[0].ToString(); 对于(int rows=0;rows_C#_Mysql_Datagridview - Fatal编程技术网

C# 如何从datagridview获取所有数据并将其插入数据库 string IdDB=“从transtbl中选择transid,其中fullname=”+textBox6.Text+”; con.选择rec(IdDB,dt); 字符串IdDB2=dt.Rows[0].ItemArray[0].ToString(); 对于(int rows=0;rows

C# 如何从datagridview获取所有数据并将其插入数据库 string IdDB=“从transtbl中选择transid,其中fullname=”+textBox6.Text+”; con.选择rec(IdDB,dt); 字符串IdDB2=dt.Rows[0].ItemArray[0].ToString(); 对于(int rows=0;rows,c#,mysql,datagridview,C#,Mysql,Datagridview,我犯了一个错误 System.NullReferenceException未处理 HResult=-2147467261 Message=对象引用未设置为对象的实例 谁来帮帮我。我试图在for循环中执行查询,但我得到的值来自gridview。感谢大家的关注:)。我只是解决了这个问题:)我只是用这个 string IdDB = "select transid from transtbl where fullname = '"+textBox6.Text+"'"; c

我犯了一个错误

System.NullReferenceException未处理 HResult=-2147467261 Message=对象引用未设置为对象的实例


谁来帮帮我。我试图在for循环中执行查询,但我得到的值来自gridview。

感谢大家的关注:)。我只是解决了这个问题:)我只是用这个

string IdDB = "select transid from transtbl where fullname = '"+textBox6.Text+"'";
                con.SelectRec(IdDB, dt);
                string IdDB2 = dt.Rows[0].ItemArray[0].ToString();

                for (int rows = 0; rows < dataGridView2.Rows.Count; rows++)
                {
                    int pProdID = int.Parse(dataGridView2.Rows[rows].Cells[0].Value.ToString());
                    string pProdName = dataGridView2.Rows[rows].Cells[1].Value.ToString();
                    double pPrice = double.Parse(dataGridView2.Rows[rows].Cells[2].Value.ToString());
                    int qQty = int.Parse(dataGridView2.Rows[rows].Cells[3].Value.ToString());
                    double tttTotal = double.Parse(dataGridView2.Rows[rows].Cells[4].Value.ToString());

                    string transdltdSql = "Insert into transdetailedtbl (transID, ProdID, ProdPrice, Qty, Total) value ("+int.Parse(IdDB2)+","+pProdID+","+pPrice+","+qQty+","+tttTotal+")";
                    con.ModRec(transdltdSql);
                } 
而不是这个

int pProdID = Convert.ToInt32(dataGridView2.Rows[rows].Cells[0].Value); 

谢谢你们的关心:)。我只是解决了这个问题:)我只是用这个

string IdDB = "select transid from transtbl where fullname = '"+textBox6.Text+"'";
                con.SelectRec(IdDB, dt);
                string IdDB2 = dt.Rows[0].ItemArray[0].ToString();

                for (int rows = 0; rows < dataGridView2.Rows.Count; rows++)
                {
                    int pProdID = int.Parse(dataGridView2.Rows[rows].Cells[0].Value.ToString());
                    string pProdName = dataGridView2.Rows[rows].Cells[1].Value.ToString();
                    double pPrice = double.Parse(dataGridView2.Rows[rows].Cells[2].Value.ToString());
                    int qQty = int.Parse(dataGridView2.Rows[rows].Cells[3].Value.ToString());
                    double tttTotal = double.Parse(dataGridView2.Rows[rows].Cells[4].Value.ToString());

                    string transdltdSql = "Insert into transdetailedtbl (transID, ProdID, ProdPrice, Qty, Total) value ("+int.Parse(IdDB2)+","+pProdID+","+pPrice+","+qQty+","+tttTotal+")";
                    con.ModRec(transdltdSql);
                } 
而不是这个

int pProdID = Convert.ToInt32(dataGridView2.Rows[rows].Cells[0].Value); 

您可能有重复的SQL注入漏洞。您不使用数据绑定的原因是什么?@Backs如果我尝试使用消息框显示它,它有值,但在使用SQL执行时,它会显示error@LucMorin据我所知,数据绑定是指从数据库获取数据。因为我将要做的是将数据从datagridview获取到DatabaseView。您可能有一个SQL注入漏洞。您不使用数据绑定的原因是什么?@Backs如果我尝试使用消息框显示它,它有值,但在使用SQL执行时,它会显示error@LucMorin据我所知,数据绑定是指如果您正在获取数据从数据库。因为我要做的是将数据从datagridview获取到数据库