首先抱歉,如果某些代码不正确。我还是新手在 vb.net 上使用 sql
我有以下代码:
Imports MySql.Data.MySqlClient
Imports System.Data.SqlClient
Public Class Form1
Private Sub btnLoad_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLoad.Click
Dim objConn As MySqlConnection
Dim objDataset As New DataSet
Dim objDataAdapter As MySqlDataAdapter
Dim myCommand As MySqlCommand
Dim sqlConn As String
objConn = New MySqlConnection("server=localhost;userid=root;database=attendance_system")
myCommand = objConn.CreateCommand
objConn.Open()
Dim objReader As MySqlDataReader = myCommand.ExecuteReader
sqlConn = "SELECT student_name FROM profile"
objDataAdapter = New MySqlDataAdapter(sqlConn, objConn)
objDataAdapter.Fill(objDataset, "profile")
MsgBox("The Connection is Now 'OPEN'")
objReader.Read()
TextBox1.Text = objReader("student_name")
objReader.Close()
objConn.Close()
End Sub
End Class
我在 phpmyadmin 中通过 vb.net 使用 MySQL 连接器,并设置了一个包含记录的数据库。连接字符串正在工作,但我的问题是当我尝试单击按钮以在文本框中加载数据时,我不断收到:
CommandText 属性未正确初始化。”
错误在这一行:
"Dim objReader As MySqlDataReader = myCommand.ExecuteReader"
我已经尝试了很多我在这个网站和其他网站上找到的修复程序。