listview怎样连接数据库并显示表中的内容?
listview怎样连接数据库并显示表中的内容?
急呀,谢谢
[解决办法]
我想这个应该对你有用,我就是这么写的
sql = "select * from tb_cookbook "
Dim struser As String = "tb_cookbook "
executesql(sql, struser)
Dim i As Integer
If mytable.Rows.Count > = 1 Then
For i = 0 To mytable.Rows.Count - 1
lvcookname.Items.Add(mytable.Rows(i).Item(0).ToString.Trim)
lvcookname.Items(i).SubItems.Add(Trim(mytable.Rows(i).Item(1)))
lvcookname.Items(i).SubItems.Add(Trim(mytable.Rows(i).Item(2)))
lvcookname.Items(i).SubItems.Add(Trim(mytable.Rows(i).Item(3)))
Next
End If
Shared Function executesql(ByVal strsql As String, ByVal sqltable As String) As Short
Dim strconn As String = "server=(local);database=hotel;integrated security=sspi "
Adapter = New SqlDataAdapter(strsql, strconn)
ds = New DataSet
Try
Adapter.Fill(ds, sqltable)
Catch ex As Exception
MsgBox(ex.Message)
End Try
mytable = ds.Tables.Item(0)
rownumberind = 0
If mytable.Rows.Count = 0 Then
Exit Function
Else
myrow = mytable.Rows.Item(rownumberind)
End If
End Function