How to work with null value
Posted on 2009-05-22
I am trying to show data in page load. but every time i am getting error. MY CODE is -
Dim SID As Integer = 0
SID = Request("SID")
Dim strSQL As String = ""
strSQL = "SELECT LID, SurveyTypeID, CentreID, CentreScore, EnquiryDate, QCat, CommentsAfterQuestion " & _
"FROM dbo.QuestionDetails WHERE LID = " & SID
Dim strCon As String = ""
strCon = "Data Source=Test; Initial Catalog=Test; Integrated Security=True"
Dim sqlCMD As SqlCommand = New SqlCommand(strSQL, New SqlConnection(strCon))
Dim dr As SqlDataReader = sqlCMD.ExecuteReader()
Do While (dr.Read())
txtSurveyTypeID.Text = dr.GetInt32(1)
txtCentreID.Text = dr.GetInt32(2)
txtCentreScore.Text = dr.GetDecimal(3)
txtEnquiryDate.Text = dr.GetDateTime(4)
txtQCat.Text = dr.GetInt32(5)
txtComments.Text = dr.GetString(6)
THE Error is -
Data is Null. This method or property cannot be called on Null values.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.
Exception Details: System.Data.SqlTypes.SqlNullValueException: Data is Null. This method or property cannot be called on Null values.
Line 37: txtSurveyTypeID.Text = dr.GetInt32(1)
Line 38: txtCentreID.Text = dr.GetInt32(2)
Line 39: txtCentreScore.Text = dr.GetDecimal(3)
Line 41: txtEnquiryDate.Text = dr.GetDateTime(4)
Please can anyone help me how to solve this probelm.
thanks in advance