Visual Web Developer 2010 how to save textbox to SQL VB.net - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Visual Web Developer 2010 how to save textbox to SQL VB.net

gs1344gs1344 Posts: 2Member
I am new to Visual Web Developer Express. Something so simple not working ....
I connected to the SQL database
Created a webpage and simply added
2 textbox(s)
a gridview (works)
Submit button

When trying the app the Submit button appears to work but no data is sent to the SQL Database Obviously I have missed something in the Vb code behind the page. ?? Any help or thoughts appreciated. I have tried multiple searches and it should work!

Protected Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

Dim SqlDataSource1 As New SqlDataSource()
Dim FailCode As New Table
Dim FailCodeDesc As New Table
Dim SqlDataSource As String = "Data Source=[my server name] ;Initial Catalog=[my database name] ;Integrated Security=True"

SqlDataSource1.InsertCommandType = SqlDataSourceCommandType.Text
SqlDataSource1.InsertCommand = "INSERT INTO ReachoutFailure (FailCode, FailDesc) Values (@FailCode, @FailDesc)"
SqlDataSource1.InsertParameters.Add("FailCode", TextBox1.Text)
SqlDataSource1.InsertParameters.Add("FailDesc", TextBox2.Text)

Dim rowsAffected As Integer = 0
Try
rowsAffected = SqlDataSource1.Insert()
Catch ex As Exception
Server.Transfer("AdminFailCode.aspx")
Finally
SqlDataSource1 = Nothing
End Try
If rowsAffected <> 1 Then
Server.Transfer("AdminFailCode.aspx")
Else
Server.Transfer("AdminFailCode.aspx")

End If
End Sub

Sign In or Register to comment.