Dim com1 As SqlCommandDim hanliang As DoubleDim isg As IntegerFor isg = 0 To 30hanliang = CDbl(DataGridView1.Rows(isg).Cells(2).Value.ToString)Dim i As IntegerFor i = 0 To 30MsgBox(DataGridView1.Rows(i).Cells(0).Value.ToString.Trim)If DataGridView1.Rows(i).Cells(2).Value.ToString.Trim = Nothing Thenhanliang = 0.0Elsehanliang = CDbl(Me.DataGridView1.Rows(i).Cells(2).Value.ToString)End IfIf TextBox1.Enabled = True Thencomstr = "insert into t_ylyys(materialid,matername,yysid,hanliang) values ('" + TextBox8.Text.ToString.Trim & TextBox2.Text.ToString.Trim + "','" + TextBox3.Text.ToString.Trim + "','" + Trim(Me.DataGridView1.Rows(i).Cells("yysid").Value.ToString) + "',' + hanliang + ')"Elsecomstr = "update t_ylyys set hanliang= ' + hanliang + ' where materialid = '" + TextBox8.Text.ToString.Trim & TextBox2.Text.ToString.Trim + "',yysid = '" + Trim(Me.DataGridView1.Rows(i).Cells("yysid").Value.ToString) + "',matername= '" + TextBox3.Text.ToString.Trim + "' "End Ifcom1 = New SqlCommand(comstr, conn)com1.ExecuteNonQuery()
想把datagridview中的內(nèi)容一次性添加到數(shù)據(jù)庫(kù),但下面的代碼在hanliang=……處總報(bào)錯(cuò)
翻翻過(guò)去那場(chǎng)雪
2023-04-01 17:13:15