I am trying to insert Supplier data into SQL database which I built inside VB.NET.
Here is the code that I am using:
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()
The problem when I enter the data, I got the Success message but when I check the database, I can't find the data !!
I checked the mdf file and I found it correct (The same one that I am using)
Any help please.