Interview Question in SQL Server 2005
Interview Question :: Insert Data to SQL from TextBox
Can someone help me with this in VB.net. I am trying to insert Data from textBox into a table in SQL 2005.
I have tried something like this, but it won't reconize SQL connection? How can I also repost the data after ONButton Click on the same page to the datagrid?
OnButton Click
Dim sqlStmt As String
Dim conString As String
Dim cn As Sqlconnection (Won't reconize SQL connection)
Dim cmd As SqlCommand (Won't reconize SQL command)
Try
sqlStmt = "insert into Table1 (FName) Values (@Fname) "
conString = "Server and connection here is correct;"
cn = New SqlConnection(conString)
cmd = New SqlCommand(sqlStmt, cn)
cmd.Parameters.Add(New SqlParameter("@FName", SqlDbType.NVarChar, 11))
cmd.Parameters("@FName").Value = TxtBoxNewRN.Text
cn.Open()
cmd.ExecuteNonQuery()
Finally
cn.Close()
End Try

Loading ...