所以我是第一次发帖,是这个网站的长期用户。每当我有问题时,我总是确保先来这里。无论如何,我正在尝试使用现有的 MySQL 数据库和 VB 中的 Visual Studio 2010 构建一个 CRM 应用程序。这是我到目前为止的代码,我正在尝试将 mysql 查询的结果返回到列表视图中,然后当有人双击一行时,它会打开该帐户。这是我到目前为止的代码。
我已经为此工作了几个小时,如果有人可以帮助我,我将不胜感激。我是 VB 的一个极端菜鸟,但对 MYSQL 来说还不错。
Imports MySql.Data.MySqlClient
Public Class mainWindow
Public sConnection As New MySqlConnection
Private Sub mainWindow_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
If sConnection.State = ConnectionState.Closed Then
sConnection.ConnectionString = "SERVER = localhost; USERID = system; PASSWORD =; DATABASE = system"
sConnection.Open()
End If
End Sub
Private Sub searchBtn_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles searchBtn.Click, Button1.Click
Dim sqlQuery As String = "Select * from tblclients"
Dim sqlAdapter As MySqlDataAdapter
Dim sqlCommand As New MySqlCommand
Dim Table As New DataTable
Dim i As Integer
With sqlCommand
.CommandText = sqlQuery
.Connection = sConnection
End With
With sqlAdapter
.SelectCommand = sqlCommand
.Fill(Table)
End With
For i = 0 To Table.Rows.Count - 1
With dataView
.Items.Add(Table.Rows(i)("id"))
With .Items(.Items.Count - 1).SubItems
.Add(Table.Rows(i)("fname"))
.Add(Table.Rows(i)("lname"))
.Add(Table.Rows(i)("company"))
.Add(Table.Rows(i)("email"))
.Add(Table.Rows(i)("phone"))
.Add(Table.Rows(i)("state"))
.Add(Table.Rows(i)("zipcode"))
End With
End With
Next
End Sub
End Class
如果有人可以再次提供帮助,我将不胜感激。