G
Guest
Hi there
I have an app with various pages running a DataReader in the Page _Load event pulling data from a database and filling text boxes.
But of coruse, if a column in the DB is blank, then the application fails and says it 'Invalid attempt to read when no data is present.'
I've tried, where possible, to implement client-side validation to gain as much information in the columns to ease this issue but I cannot implement in all instances and there will be some columns blank which will cause this error.
There is a suggestion I use a 'IsDbNull' - but I am not sure how to use that in this context; also a DB column could be simple 'blank' and not NULL.
Example code is as follows:
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
cn = New SqlConnection("xx")
cn.Open()
cmd = New SqlCommand("SELECT * FROM memberDetails WHERE Email=@Email", cn)
cmd.parameters.add("@Email", EmailVariable)
rdr = cmd.ExecuteReader()
rdr.Read()
txtFName.Text = rdr("FName")
txtSName.Text = rdr("SName")
txtDoB.Text = rdr("DoB")
rdr.Close()
I'm looking for a solution please but ideally an example of some code I can use to solve the issue.
Thanks in adnace; I'll be continually checking back into the forum for updates.
I have an app with various pages running a DataReader in the Page _Load event pulling data from a database and filling text boxes.
But of coruse, if a column in the DB is blank, then the application fails and says it 'Invalid attempt to read when no data is present.'
I've tried, where possible, to implement client-side validation to gain as much information in the columns to ease this issue but I cannot implement in all instances and there will be some columns blank which will cause this error.
There is a suggestion I use a 'IsDbNull' - but I am not sure how to use that in this context; also a DB column could be simple 'blank' and not NULL.
Example code is as follows:
Dim cn As SqlConnection
Dim cmd As SqlCommand
Dim rdr As SqlDataReader
cn = New SqlConnection("xx")
cn.Open()
cmd = New SqlCommand("SELECT * FROM memberDetails WHERE Email=@Email", cn)
cmd.parameters.add("@Email", EmailVariable)
rdr = cmd.ExecuteReader()
rdr.Read()
txtFName.Text = rdr("FName")
txtSName.Text = rdr("SName")
txtDoB.Text = rdr("DoB")
rdr.Close()
I'm looking for a solution please but ideally an example of some code I can use to solve the issue.
Thanks in adnace; I'll be continually checking back into the forum for updates.