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
Answers to "Insert Data to SQL from TextBox"
RE: Insert Data to SQL from TextBox?

make sure you have

Imports System.Data.SqlClient



with your other imports.
 
Vote for this answer ::  
RE: Insert Data to SQL from TextBox?

don't use direct datalinks, it's easyer to use and execute query statments.



the rough code would be:

[update table set fname = ']+textbox1.text+[' where counter = ]+lnrow+[ ]
 
Vote for this answer ::  
Update Alert Setting