首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > VB Dotnet >

求高手帮忙看下 程序的有关问题 ~

2012-01-22 
求高手帮忙看下 程序的问题 ~~~~~我想根据listbox中的项选出表中对应的记录我先将listbox中的项存入数组,

求高手帮忙看下 程序的问题 ~~~~~
我想根据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) 

热点排行