我有一个MySQL对象我试图从中选择所有数据并插入到数据表中但是每次它到达我关于所述数据表的第一个if语句时它会得到一个可能的空值错误
dbfile dbserver dbuser和dbpassw都是在模块上设置的公共变量。
可变维度
Dim cnn As New MySqlConnection()
Dim cmd As New MySqlCommand
Dim adptr As New MySqlDataAdapter
Dim filltab As DataTable
码
Dim cb As New MySqlConnectionStringBuilder
cb.Database = dbfile
cb.Server = dbserver
cb.UserID = dbuser
cb.Password = dbpassw
Using cnn As New MySqlConnection(cb.ConnectionString)
Using cmd As New MySqlCommand("SELECT * from gpstracking", cnn)
Try
cnn.Open()
adptr = New MySqlDataAdapter(cmd)
adptr.Fill(filltab)
Catch ex As Exception
MsgBox(ex.ToString)
End Try
If filltab.Rows.Count > 0 Then 'this is the row that the error for filltab being a null value hits
pop = 0
For pop As Integer = 0 To filltab.Rows.Count - 1
' WebBrowser1.Document.InvokeScript("AddMarker", New Object() {"Unit: " & filltab.Rows(pop)("unitnumb") & " at " & filltab.Rows(pop)("time"), filltab.Rows(pop)("lat"), table.Rows(pop)("long")})
Next
End If
End Using
End Using
上的一个错误
adptr.Fill(filltab) 'Exception:Thrown: "Value cannot be null." (System.ArgumentNullException)
我也注意到它正在宣布"未能收集细节"在
Catch ex As Exception
MsgBox(ex.ToString)
End Try
答案 0 :(得分:2)
我不知道vb语法,但你有Dim filltab As DataTable
没有 New (就像在其他方面一样),我猜 MySqlDataAdapter.Fill 需要参数不为空。只是一个猜测。
答案 1 :(得分:0)
而不是使用此代码
adptr = New MySqlDataAdapter(cmd)
adptr.Fill(filltab)
尝试使用
filltab.load(cmd.ExecuteReader())