i'm trying to insert some sample data into a sql server.
I'm using Visual Basic 2010 Express.
Here's the code:
Public Sub insert()
Dim myconnect As New SqlClient.SqlConnection
myconnect.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\DATABASE_NUOVO.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True"
Dim mycommand As SqlClient.SqlCommand = New SqlClient.SqlCommand()
mycommand.Connection = myconnect
mycommand.CommandText = "INSERT INTO utenti (nome) VALUES ('mario')"
myconnect.Open()
Try
mycommand.ExecuteNonQuery()
Catch ex As System.Data.SqlClient.SqlException
MsgBox(ex.Message)
End Try
myconnect.Close()
MsgBox("Success")
End Sub
The code seems to run correctly, but when i look into the database after running the debug i don't see the sample data.
Where is the problem?
Thanks
Catchto just SqlExceptions. There are other kinds of exceptions that can be thrown here.