Imports System.Data.SqlClient
Public Class Form1
Dim conn As SqlConnection
Dim comm As SqlCommand
Private Function GetConnection() As SqlConnection
Return New SqlConnection(My.Settings.SalesConnectionString)
End Function
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Try
conn = GetConnection()
conn.Open()
comm = New SqlCommand(TextBox1.Text, conn)
comm.ExecuteNonQuery()
conn.Close()
MsgBox("语句运行成功!")
Catch ex As Exception
MsgBox("有错误")
End Try
End Sub
'用于测试的SQL语句
'select * from grade where 姓名='%王%'
'INSERT INTO grade(学号, 姓名, 语文, 数学, 英语) VALUES (221, '萧何', 90, 50,80)
'UPDATE grade SET 姓名 = '蔺相如' WHERE 姓名 = '萧何'
'DELETE FROM grade WHERE 姓名 = '蔺相如'
End Class