G
Guest
Hi there.
I have various pages in an ASP.NET applicaiton and in the Page_load event I have data being read from a SQL DB filling textboxes on the page
Now, sometimes the fields in the DB will be blank and I would a 'Invalid attempt to read when no data is present.' error.
I have tried to implement validation in pages to ease this issue but I need a solution which covers just the below - reading a DB where it doesn't fail (I have received suggestions before, but never examples of code).
Code I have:
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
cn = New SqlConnection("xxx")
cmd = New SqlCommand("SELECT * FROM MemberTable WHERE Email=@Email", cn)
cmd.Parameters.Add("@Email", EmailVar)
cn.Open()
rdr = cmd.ExecuteReader()
rdr.Read()
txt1.Text = "" & rdr("FirstName")
txt2.Text = "" & rdr("LastName")
txt3.Text = "" & rdr("dateOfBirth")
rdr.Close()
Many thanks
I have various pages in an ASP.NET applicaiton and in the Page_load event I have data being read from a SQL DB filling textboxes on the page
Now, sometimes the fields in the DB will be blank and I would a 'Invalid attempt to read when no data is present.' error.
I have tried to implement validation in pages to ease this issue but I need a solution which covers just the below - reading a DB where it doesn't fail (I have received suggestions before, but never examples of code).
Code I have:
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
cn = New SqlConnection("xxx")
cmd = New SqlCommand("SELECT * FROM MemberTable WHERE Email=@Email", cn)
cmd.Parameters.Add("@Email", EmailVar)
cn.Open()
rdr = cmd.ExecuteReader()
rdr.Read()
txt1.Text = "" & rdr("FirstName")
txt2.Text = "" & rdr("LastName")
txt3.Text = "" & rdr("dateOfBirth")
rdr.Close()
Many thanks