insert into sql server vb.net
Posted on 2013-01-18
Hello there. This is my question. After searching the web I found this code for inserting a new record into an SQL Server db, from a control behind VB.NET
Dim con As New SqlConnection
Dim cmd As New SqlCommand
con.ConnectionString = "Data Source=CDPC1093\CDPC1093;Initial Catalog=tba210;Integrated Security=True"
cmd.Connection = con
cmd.CommandText = "INSERT INTO T_USR(N_USER_NO, S_NAME,S_USER_TYPE,D_REG,D_PERIOD_ST,D_PERIOD_END) VALUES (" & Gedetineerde_systeem_ID.Text & ", '" & Achternaam.Text & "' ,2," & Today & "," & Today & "," & DateAdd(DateInterval.Year, 1, Today)
Catch ex As Exception
MessageBox.Show("Error while inserting record on table..." & ex.Message, "Insert Records")
The fact is that I am always getting back the error message, meaning the insertion was not successful.
Could any of you guys give me a hand on this? What am I doing wrong or letting behind?