I have a weird problem: I'm trying to do some basic procedure to insert data in a database and I don't know what it's happening, but it does not work.
The thing is that I have a database called prova3 that is a SQL Server 2012 database created with vb.net 2013 with a table called tabela. I created a dataset to see the connection string that is stored in app.config. The string is the same below. I'm not getting an error, but the data is not inserted. When I go to the Server explorer to see the data in the table, it's empty.
I think the data it's been saved in elsewhere, but I don't know how to fix it, because I think I'm coding this right. This is for vb.net, but I did the same code for asp.net and it works. Weird.
Could you help me?
In the form it's only a textbox1 and a button1 controls. There is no more code.
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ImageUrlSt As String
Dim command1 As New SqlCommand
Dim con As New SqlConnection
ImageUrlSt = TextBox1.Text
Try
con.ConnectionString = "Data Source=(LocalDB)\v11.0;AttachDbFilename=|DataDirectory|\Prova3.mdf;Integrated Security=True"
con.Open()
command1.Connection = con
command1.CommandText = "INSERT INTO Tabela (imageurl) VALUES (@imageurlst)"
command1.Parameters.Add(New SqlParameter("@imageurlst", ImageUrlSt))
command1.ExecuteNonQuery()
MsgBox("News Saved Succesfully")
Catch ex As Exception
MsgBox(ex.Message)
Finally
con.Close()
End Try
End Sub
Tablethe name of your table? It is an SQL keyword, how did you use that name for your table?|DataDirectory|as path is problematic when debugging. Did you check the db copy at\bin\debug?