VB.NET访问ACCESS数据库,查询时,提示dr = cmd.ExecuteReader()至少一个参数没被指定值
ImportsSystem.Data.OleDbPublicClassForm1PrivateSubButton1_Click(ByValsenderAsSystem.O...
Imports System.Data.OleDb
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDbConnection
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=test.mdb"
Dim table As New DataTable()
Dim myda As New OleDbDataAdapter("select * from test", con)
Dim ds As New DataSet()
Dim cmd As New OleDbCommand
'定义一个OLEDBReader方法来读取数据库
Dim dr As OleDbDataReader
con.Open()
cmd.Connection = con
myda.Fill(ds, "test")
myda.Fill(table)
ComboBox1.DataSource = ds
Me.DataGridView1.DataSource = table
Me.ComboBox1.DisplayMember = "test.设备"
cmd.CommandText = "select ip from test where 设备=" & ComboBox1.Text & ""
dr = cmd.ExecuteReader()
If dr.Read() Then
TextBox1.Text = dr(0)
End If
'完成后关闭dr.con等释放资源
dr.Close()
con.Close()
End Sub
End Class
-----------------------执行时,总提示dr = cmd.ExecuteReader()至少一个参数没被指定值,请问各位大侠,这个是怎么回事呢?该怎么解决? 展开
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim con As New OleDbConnection
con.ConnectionString = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=test.mdb"
Dim table As New DataTable()
Dim myda As New OleDbDataAdapter("select * from test", con)
Dim ds As New DataSet()
Dim cmd As New OleDbCommand
'定义一个OLEDBReader方法来读取数据库
Dim dr As OleDbDataReader
con.Open()
cmd.Connection = con
myda.Fill(ds, "test")
myda.Fill(table)
ComboBox1.DataSource = ds
Me.DataGridView1.DataSource = table
Me.ComboBox1.DisplayMember = "test.设备"
cmd.CommandText = "select ip from test where 设备=" & ComboBox1.Text & ""
dr = cmd.ExecuteReader()
If dr.Read() Then
TextBox1.Text = dr(0)
End If
'完成后关闭dr.con等释放资源
dr.Close()
con.Close()
End Sub
End Class
-----------------------执行时,总提示dr = cmd.ExecuteReader()至少一个参数没被指定值,请问各位大侠,这个是怎么回事呢?该怎么解决? 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询