Hi
I have to display the data from SQL Server table to the frontend textboxes during the page load. For that I have given the coding as,
Imports System.Data
Imports System.Data.Sql Client
Partial Class Default2
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim str, str1 As String
str = "user id=sa;password= cast;database=j sc;server=AUROR A-SERVER"
con = New SqlConnection(s tr)
Try
con.Open()
Catch
End Try
str1 = "select * from login"
cmd = New SqlCommand(str1 , con)
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteRead er()
While (dr1.Read())
txtLoginId2 = dr1.GetValue(0)
txtPassword1 = dr1.GetValue(1)
txtConfirmPassw ord = dr1.GetValue(2)
txtFirstName = dr1.GetValue(3)
txtLastName = dr1.GetValue(4)
txtAddress = dr1.GetValue(5)
txtAddress2 = dr1.GetValue(6)
txtAddress3 = dr1.GetValue(7)
txtCity = dr1.GetValue(8)
txtCountry = dr1.GetValue(9)
txtProvince = dr1.GetValue(10 )
txtPostalCode = dr1.GetValue(11 )
txtPhone = dr1.GetValue(12 )
txtEmail1 = dr1.GetValue(13 )
txtHow = dr1.GetValue(14 )
End While
End Sub
End Class
But if I run the project it shows the error as
Unable to cast object of type 'System.String' to type 'System.Web.UI. WebControls.Tex tBox'.
Invalid CastException was unhandled by user code.
I have to display the data from SQL Server table to the frontend textboxes during the page load. For that I have given the coding as,
Imports System.Data
Imports System.Data.Sql Client
Partial Class Default2
Inherits System.Web.UI.P age
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArg s) Handles Me.Load
Dim con As SqlConnection
Dim cmd As SqlCommand
Dim str, str1 As String
str = "user id=sa;password= cast;database=j sc;server=AUROR A-SERVER"
con = New SqlConnection(s tr)
Try
con.Open()
Catch
End Try
str1 = "select * from login"
cmd = New SqlCommand(str1 , con)
Dim dr1 As SqlDataReader
dr1 = cmd.ExecuteRead er()
While (dr1.Read())
txtLoginId2 = dr1.GetValue(0)
txtPassword1 = dr1.GetValue(1)
txtConfirmPassw ord = dr1.GetValue(2)
txtFirstName = dr1.GetValue(3)
txtLastName = dr1.GetValue(4)
txtAddress = dr1.GetValue(5)
txtAddress2 = dr1.GetValue(6)
txtAddress3 = dr1.GetValue(7)
txtCity = dr1.GetValue(8)
txtCountry = dr1.GetValue(9)
txtProvince = dr1.GetValue(10 )
txtPostalCode = dr1.GetValue(11 )
txtPhone = dr1.GetValue(12 )
txtEmail1 = dr1.GetValue(13 )
txtHow = dr1.GetValue(14 )
End While
End Sub
End Class
But if I run the project it shows the error as
Unable to cast object of type 'System.String' to type 'System.Web.UI. WebControls.Tex tBox'.
Invalid CastException was unhandled by user code.
Comment