我的数据集不断进入
Catch ex As Exception.
我不知道问题是什么。 有人能帮助我吗?
Public Function Tifcheck(zoektif As String) As Boolean
Dim cmd2 As New OleDbCommand
Dim con2 As New OleDbConnection
Dim cmd3 As New OleDbDataAdapter
Dim ds As New DataSet
Try
con2.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\klaasjelle\Documents\Database3.accdb"
con2.Open()
cmd2.CommandText = "SELECT * From Data Where Tif = '" + zoektif +
"'"
cmd3 = New OleDbDataAdapter(Tifcheck, zoektif)
cmd3.Fill(ds)
MsgBox(ds.Tables(2).Rows.Count)
Catch ex As Exception
MsgBox("fout")
End Try
con2.Close()
Return Tifcheck
End Function
我希望你能得到什么,你看到了错误吗? 或者只是我的代码。 请告诉我。
答案 0 :(得分:1)
您缺少添加与命令的连接。
cmd2.Connection = con2
在您的代码中添加了上面的行。
Public Function Tifcheck(zoektif As String) As Boolean
Dim cmd2 As New OleDbCommand
Dim con2 As New OleDbConnection
Dim cmd3 As New OleDbDataAdapter
Dim ds As New DataSet
Try
con2.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\klaasjelle\Documents\Database3.accdb"
con2.Open()
cmd2.CommandText = "SELECT * From Data Where Tif = '" + zoektif + "'"
cmd2.Connection = con2
cmd3 = New OleDbDataAdapter(Tifcheck, zoektif)
cmd3.Fill(ds)
MsgBox(ds.Tables(2).Rows.Count)
Catch ex As Exception
MsgBox("fout")
End Try
con2.Close()
Return Tifcheck
End Function