0

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

I am new to Visual Web Developer Express

I connected the SQL
Created a webpage and simply added
2 textbox(s)
a gridview (works)
Submit button

When trying the app the Submit button, The page resets, it 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 or so I thought!

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

Edited by pritaeas: Moved

3
Contributors
2
Replies
8
Views
5 Years
Discussion Span
Last Post by geniusvishal
0

Well the easiest way to know what is happening is to debug your codes during execution.. Check the flow and you would be able to know what is happening.. Second thing check your connection string and verify whether the data is getting inserted in the correct database..

Thank You.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.