任何人都可以帮我解决这个SQL错误吗? 如何使用xampp将其连接到phpmyadmin中的数据库? 如果您认为我的代码有问题,请随时更正我的代码。
Imports System.Data.SqlClient
Imports MySql.Data.MySqlClient
Public Class Form1
Dim con As SqlConnection
Dim com As SqlCommand
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
con = New SqlConnection
con = New SqlCommand
con.ConnectionString = "initial catalog=student;user id=sa;pwd="
con.Open()
con.Connection = con
End Sub
Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
If TextBox1.Text = " " Or TextBox2.Text = " " Or TextBox3.Text = " " Then
MsgBox("Please fill all the details")
Exit Sub
End If
com.CommandText = "insert into stud values('" & TextBox1.Text & "','" & TextBox2.Text & "','" & TextBox3.Text & "')"
com.ExecuteNonQuery()
MsgBox("1 record is stored successfully")
TextBox1.Clear()
TextBox2.Clear()
TextBox3.Clear()
End Sub
End Class
答案 0 :(得分:0)
您应该使用 MySqlConnection ,而不是SqlConnection。 SqlConnection用于SQL Server。它可以从Nuget包下载。