盯着这段代码2个小时,我找不到任何东西。它可能来自疲劳。当我运行代码时,错误指向
strSelect = "SELECT * FROM TGolfers where strFirstName like '%" &
cboGolfer.Text & "%' or strLastName like '%" & cboGolfer.Text & "%'"
cmdSelect = New OleDb.OleDbCommand(strSelect, m_conAdministrator)
drSourceTable = cmdSelect.ExecuteReader
Using dt As New DataTable()"
GetGolfer函数中的希望有人可以帮我弄清楚为什么我会收到此错误并修复它。谢谢
Public Class frmGolfer
Private Sub frmGolfer_Load(sender As Object, e As EventArgs) Handles
MyBase.Load
GetGolfer()
Try
Dim strSelect As String = ""
Dim cmdSelect As OleDb.OleDbCommand
Dim drSourceTable As OleDb.OleDbDataReader
Dim dt As DataTable = New DataTable
Dim strSQL As String = "INSERT INTO TGolfers(strFirstName, strLastName, strEmail) VALUES (@FirstName, @LastName, @Email)"
If OpenDatabaseConnectionSQLServer() = False Then
MessageBox.Show(Me, "Database connection Error." & vbNewLine &
"The application will now close.",
Text + "Error",
MessageBoxButtons.OK, MessageBoxIcon.Error)
Me.Close()
End If
cboGolfer.BeginUpdate()
strSelect = "Select intGolferID, strLastName FROM TGolfers"
cmdSelect = New OleDb.OleDbCommand(strSelect, m_conAdministrator)
drSourceTable = cmdSelect.ExecuteReader
dt.Load(drSourceTable)
cboGolfer.ValueMember = "intGolferID"
cboGolfer.DisplayMember = "strLastName"
cboGolfer.DataSource = dt
cboGolfer.EndUpdate()
drSourceTable.Close()
CloseDatabaseConnection()
Catch excError As Exception
MessageBox.Show(excError.Message)
End Try
If cboGolfer.Items.Count > 0 Then cboGolfer.SelectedIndex = 0
End Sub
Public Function GetGolfer()
Dim strSelect As String = ""
Dim cmdSelect As OleDb.OleDbCommand
Dim drSourceTable As OleDb.OleDbDataReader
strSelect = "SELECT * FROM TGolfers where strFirstName like '%" & cboGolfer.Text & "%' or strLastName like '%" & cboGolfer.Text & "%'"
cmdSelect = New OleDb.OleDbCommand(strSelect, m_conAdministrator)
drSourceTable = cmdSelect.ExecuteReader
Using dt As New DataTable()
DgvGolfer.AutoGenerateColumns = False
DgvGolfer.DataSource = dt
End Using
End Function