我想根据listbox中的项选出表中对应的记录 我先将listbox中的项存入数组,再遍历数组,连接表,从表中选出对应记录放到dataset中 可以这样吗???一运行就有错啊~~~
Dim i As Integer
Dim t As Integer
Dim s() As String
t = ListBox1.Items.Count
ReDim s(t - 1)
For i = 0 To t - 1
s(i) = ListBox1.Items(i)
Next
Dim str As String
For Each str In s
conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=lvyou1.mdb"
comm.CommandText = "select * from 景点 where name=" + str
comm.Connection = conn
dap.SelectCommand = comm
conn.Open()
dap.Fill(da)
conn.Close()
Next
Dim dt3 As New DataTable
dt3 = da.Tables(0)
------解决方案--------------------
- VB.NET code
Dim i As Integer Dim t As Integer t = ListBox1.Items.Count Dim s(t-1) As String For i = 0 To t - 1 s(i) = ListBox1.Items(i) Next Dim str As String conn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=lvyou1.mdb" comm.Connection = conn For Each str In s comm.CommandText = "select * from 景点 where name= '" + str + "'" dap.SelectCommand = comm dap.Fill(da) Next Dim dt3 As DataTable = da.Tables(0)