我试图从用户那里收集输入,根据我的数据库检查它,看看它是否存在于数据库中。如果是这样的话,程序应该获取相应个人的姓、名和费用并输出。
验证码:
Imports Mysql.Data.MySqlClient
Public Class Form1
Dim reader As MySqlDataReader
Dim command As New MySqlCommand
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim myConnectionString As String
myConnectionString = "server=localhost;" _
& "uid=root;" _
& "pwd=Emma@21*GCTU;" _
& "database=dummystudents"
Try
Dim conn As New MySql.Data.MySqlClient.MySqlConnection(myConnectionString)
conn.Open()
Dim sql As String = "SELECT idstudents FROM students WHERE idstudents = @TextBox1.Text "
command = New MySqlCommand(sql, conn)
reader = command.ExecuteReader()
If reader.Read() Then
TextBox2.Text = reader(1)
TextBox3.Text = reader(2)
TextBox4.Text = reader(3)
End If
Catch ex As MySql.Data.MySqlClient.MySqlException
MessageBox.Show(ex.Message)
End Try
End Sub
End Class
1条答案
按热度按时间wrrgggsh1#
下面是你的SQL代码:
当
idstudents
是你输入的值时,把idstudents
拉出来有什么意义?更糟糕的是,这就是你所做的一切,然后你这样做:这需要你至少撤回四列。
注解中提到的修改可能会让您的代码执行,但这不是正确的方法。看起来您尝试使用参数但失败了。这样做,但要做对,即。