在 System.Data.SqlClient.SqlException 中第一次偶然出现的“System.Data.dll”类型的异常 5
ImportsSystem.Data.SqlClientPublicClassForm1DimconnAsSqlConnectionDimdaAsSqlDataAdapt...
Imports System.Data.SqlClient
Public Class Form1
Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xuehao = TextBox1.Text
Dim xingming = TextBox4.Text
Dim yuwen = TextBox3.Text
Dim shuxue = TextBox2.Text
Dim yingyu = TextBox5.Text
Try
conn = New SqlConnection()
conn.ConnectionString = "data source=(local);initial catalog=sales;integrated security=false;user id=sa;password=aa"
conn.Open()
Dim strSQL As String
strSQL = "insert into grade(学号,姓名,语文,数学,英语) values ('" & xuehao & "','" & xingming & "','" & yuwen & "','" & shuxue & "','" & yingyu & "')"
MessageBox.Show(strSQL)
Dim comm As New SqlCommand(strSQL, conn)
comm.ExecuteNonQuery()
conn.Close()
MessageBox.Show("数据添加成功!")
Catch
MessageBox.Show("数据库连接有误!")
End Try
End Sub 展开
Public Class Form1
Dim conn As SqlConnection
Dim da As SqlDataAdapter
Dim ds As DataSet
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim xuehao = TextBox1.Text
Dim xingming = TextBox4.Text
Dim yuwen = TextBox3.Text
Dim shuxue = TextBox2.Text
Dim yingyu = TextBox5.Text
Try
conn = New SqlConnection()
conn.ConnectionString = "data source=(local);initial catalog=sales;integrated security=false;user id=sa;password=aa"
conn.Open()
Dim strSQL As String
strSQL = "insert into grade(学号,姓名,语文,数学,英语) values ('" & xuehao & "','" & xingming & "','" & yuwen & "','" & shuxue & "','" & yingyu & "')"
MessageBox.Show(strSQL)
Dim comm As New SqlCommand(strSQL, conn)
comm.ExecuteNonQuery()
conn.Close()
MessageBox.Show("数据添加成功!")
Catch
MessageBox.Show("数据库连接有误!")
End Try
End Sub 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询