Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Thanks,

Tehon

  • Moderators
Posted

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

Visit...Bassic Software
Posted
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.

Thanks,

Tehon

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...