tehon3299 Posted February 2, 2003 Posted February 2, 2003 Hey - I was just wondering how I would use the SQL Insert Command on an ASPX page. I know it's: INSERT INTO tableName VALUES ______. How do I use the value from a textbox on the page as the insert value? Thanks Quote Thanks, Tehon
Moderators Robby Posted February 3, 2003 Moderators Posted February 3, 2003 Using an SqlCommand and the .ExecuteNonQuery() method, then ... "INSERT INTO tableName (field1) VALUES ('" & textBox1.text & "')" Quote Visit...Bassic Software
tehon3299 Posted February 3, 2003 Author Posted February 3, 2003 OK...Thanks for the help. Now, where do I use the ExecuteNonQuery() Command? Where does that have to go? Thanks Quote Thanks, Tehon
Moderators Robby Posted February 3, 2003 Moderators Posted February 3, 2003 You can call the function from a button click... Protected Friend Function SetTableValue(ByVal sSql As String) As Integer 'pass the INSERT INTO statement as the argument (as sSql) Dim cmd As SqlCommand Dim con As New SqlConnection("Your connection String") Dim recordsAffected As Integer Try If con.State = ConnectionState.Closed Then con.Open() cmd = New SqlCommand(sSql, con) recordsAffected = cmd.ExecuteNonQuery() Catch recordsAffected = -1 Finally If con.State = ConnectionState.Open Then con.Close() If Not cmd Is Nothing Then cmd.Dispose() End Try Return recordsAffected End Function Quote Visit...Bassic Software
tehon3299 Posted February 3, 2003 Author Posted February 3, 2003 Here's my code. I have it in a button click. Can you see what is wrong? It inserts a blank field in SQL but NOT a NULL. I allow NULLS for the field but I just get a blank field. Quote Thanks, Tehon
Moderators Robby Posted February 3, 2003 Moderators Posted February 3, 2003 Can you Zip a text file instead, thanks. Quote Visit...Bassic Software
tehon3299 Posted February 3, 2003 Author Posted February 3, 2003 Here ya go:trans.zip Quote Thanks, Tehon
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.