想把datagridview中的内容一次性添加到数据库,但下面的代码在hanliang=……处总报错

Dim com1 As SqlCommand
Dim hanliang As Double
Dim isg As Integer
For isg = 0 To 30
hanliang = CDbl(DataGridView1.Rows(isg).Cells(2).Value.ToString)

Dim i As Integer
For i = 0 To 30
MsgBox(DataGridView1.Rows(i).Cells(0).Value.ToString.Trim)
If DataGridView1.Rows(i).Cells(2).Value.ToString.Trim = Nothing Then
hanliang = 0.0
Else
hanliang = CDbl(Me.DataGridView1.Rows(i).Cells(2).Value.ToString)
End If

If TextBox1.Enabled = True Then
comstr = "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 + ')"
Else
comstr = "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 If

com1 = New SqlCommand(comstr, conn)
com1.ExecuteNonQuery()

翻翻过去那场雪
浏览 111回答 2
2回答

倚天杖

#include<iostream>#include<string>#include<fstream>#include<sstream>using namespace std;class Tair //通过定义一个类来定义数据录入的函数&nbsp;{&nbsp;char flight[20]; char data[20];char start[20];char finish[20];char stime[20];char ftime[20];int price;

心有法竹

你可用DataTable 试试 ··! 必须行的~~~
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

MySQL