Imports System.Data
Imports System.Data.SqlClient
Public Class Reservation
Dim sqlConn As SqlConnection
Private Sub Reservation_Load(sender As Object, e As EventArgs) Handles MyBase.Load
sqlConn = New SqlConnection("Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|EasyReserv.mdf;Integrated Security=True")
End Sub
Private Sub btnSubmit_Click(sender As Object, e As EventArgs) Handles btnSubmit.Click
Dim addSQL As String = "INSERT INTO CUSTOMER ( customerID, name, contactNumber, email) VALUES (1, 'James', '012444444','[email protected]')"
Dim addCmd As SqlCommand = New SqlCommand(addSQL, sqlConn)
sqlConn.Open()
addCmd.ExecuteNonQuery()
sqlConn.Close()
End Sub
End Class
代碼內部沒有錯誤,並且ExecuteNonQuery
也返回1,但在我的數據庫中沒有記錄。無法使用VB.net更新SQL Server
調試如果更改,會發生什麼'customerID'的數據類型添加'identity',然後在插入後立即查詢'SCOPE_IDENTITY()'? – Dai
數據庫仍未更新 – user2477598
如何檢查記錄是否被插入?你在使用VS IDE中的Server Explorer查看你的表嗎?如果是這樣,服務器資源管理器使用的連接字符串與應用程序使用的連接字符串相同? – Steve