我正在使用MS SQL并尝试使用vb.net运行查询
我想得到像
这样的数据
101个
102个
...
110个
111
...
我在MS SQL中执行的查询是
select Book_Code, Book_Name from famsetup where book_code like '1%'
这样运行正常并给我正确的结果......
当我在下面的vb.net中编写以下代码时,
ListViewBound(LstViewHelp, "Select Book_Code, Book_Name from FAMSETUP where Book_Code like '1%'", con1)
我没有任何价值......
注意: - Listviewbound是我的功能,并且在我的程序中的其他地方正常工作,我只是展示了这一全线......
我的查询错误写在vb.net ???
我应该在vb.net中写什么查询???
接受任何帮助......! :/
其他代码是
Listviewbound
Sub ListViewBound(lvw As ListView, QRY As String, Xcn As SqlConnection)
Try
cmd = New SqlCommand(QRY, Xcn)
da = New SqlDataAdapter(cmd)
dt = New DataTable
Dim ListView1 As ListView = New ListView
da.Fill(dt)
lvw.View = View.Details
lvw.GridLines = True
lvw.Columns.Clear()
lvw.Items.Clear()
For Each col As DataColumn In dt.Columns
lvw.Columns.Add(col.ToString)
Next
For Each row As DataRow In dt.Rows
Dim lst As ListViewItem
lst = lvw.Items.Add(If(row(0) IsNot Nothing, row(0).ToString, ""))
For i As Integer = 1 To dt.Columns.Count - 1
lst.SubItems.Add(If(row(i) IsNot Nothing, row(i).ToString, ""))
Next
Next
For i = 0 To lvw.Items.Count - 1
If i Mod 2 Then
lvw.Items(i).BackColor = Color.White
Else
lvw.Items(i).BackColor = Color.LightBlue
End If
Next
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub
连接字符串代码
Sub CompDb_Open()
Try
con1.ConnectionString = "Data Source=.\sqlexpress;Initial Catalog=bonny;Integrated Security=True"
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End Sub