VB.NET内に構築したSQLデータベースにサプライヤーデータを挿入しようとしています。
私が使用しているコードは次のとおりです。
Dim myconnect As New SqlClient.SqlConnection
myconnect.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DB\InvDB.mdf;Integrated Security=True;User Instance=True"
Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
mycommand.Connection = myconnect
mycommand.CommandText = "INSERT INTO Supplier (SupplierID, Name, Email,Phone,Address,City) VALUES (@SID, @Name, @Email, @Phone, @Address, @City)"
myconnect.Open()
Try
mycommand.Parameters.Add("@SID", SqlDbType.Int).Value = SIDTextBox.Text
mycommand.Parameters.Add("@Name", SqlDbType.NVarChar).Value = NameTextBox.Text
mycommand.Parameters.Add("@Email", SqlDbType.VarChar).Value = EmailTextBox.Text
mycommand.Parameters.Add("@Phone", SqlDbType.VarChar).Value = PhoneTextBox.Text
mycommand.Parameters.Add("@Address", SqlDbType.NVarChar).Value = AddressTextBox.Text
mycommand.Parameters.Add("@City", SqlDbType.NVarChar).Value = CityTextBox.Text
mycommand.ExecuteNonQuery()
MsgBox("Success")
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
myconnect.Close()
データを入力するときの問題、Successメッセージが表示されましたが、データベースを確認するとデータが見つかりません!!
mdfファイルをチェックしたところ、正しいことがわかりました(使用しているものと同じです)
助けてください。