Hi I am working with a web application where I am selecting values from a SQL Server 2005 database and then loading the values into different controls on my page. Most of the values load with no problem, except for those columns where the value of the selected row in the column could be a null. I get the following error message:
The value for column 'COLUMN NAME' in table 'TABLE NAME' is DBNull.
I've tried in my Sql select statement to use the following: IsNull(Column_N ame, ' '), but I still get the error message. Can anyone tell me how to get around this error message?
Here is my web service with my ADO.NET code:
And then this is the code where I call the web service and populate the controls:
There are 4 columns where the value can be null: PilotEvaltrID, SOEvaltrID, FltNbr, FltZDate.
Can anyone offer me a solution?
The value for column 'COLUMN NAME' in table 'TABLE NAME' is DBNull.
I've tried in my Sql select statement to use the following: IsNull(Column_N ame, ' '), but I still get the error message. Can anyone tell me how to get around this error message?
Here is my web service with my ADO.NET code:
Code:
<WebMethod()> _
Public Function WebService2(ByVal SessionID As Integer, ByVal SessionMonth As String, ByVal SessionType As String, ByVal Program As String, ByVal PilotEvaltrID As Integer, ByVal SOEvaltrID As Integer, ByVal MinLevel As Integer, ByVal IssuedCA As Boolean, ByVal IssuedFO As Boolean, ByVal IssuedSO As Boolean, ByVal FltNbr As Integer, ByVal FltZDate As String, ByVal Path As String) As DataSet1
' Creates a new DataSet, a connection to data source named sqlConn, and a data adapter named sqlDA
Dim DS2 As DataSet1
Dim sqlConn As SqlConnection
Dim sqlDA As SqlDataAdapter
Dim value As Boolean
' creates a new connection to DB
sqlConn = New SqlConnection("Data Source=S11694;Initial Catalog=svtppdbSQL;Integrated Security=True")
sqlConn.Open()
' New instance of sqlDA used to fill the DataSet
sqlDA = New SqlDataAdapter("select SessionMonth, SessionType, Program, PilotEvaltrID, SOEvaltrID, MinLevel, IssuedCA, IssuedFO, IssuedSO, FltNbr, FltZDate from tblSessionID where SessionID = '" & SessionID & "'", sqlConn)
' New instance of DataSet
DS2 = New DataSet1
'Disables EnforceConstraints
value = DS2.EnforceConstraints
DS2.EnforceConstraints = False
' fills the DataAdapter object with information from tblSessionID
sqlDA.Fill(DS2.tblSessionID)
' Returns the DataSet for the function
Return DS2
sqlConn.Close()
End Function
Code:
Try
' Declares variable TempPath and creates new instance of clsWebServices serviceObj
Dim TempPath As String
Dim serviceObj As New clsWebServices
' creates new instance of DataSet
Dim dsFind2 As New DataSet1
TempPath = Server.MapPath("svtppdbSQL.mdf") 'Creates specifies MapPath for variable TempPath to svtppdbSQL
' Specifies search criteria
dsFind2 = serviceObj.WebService2(Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, Me.ddlSessionID.Text, TempPath)
'Returns rows > than 0 in tblSessionID
If dsFind2.tblSessionID.Rows.Count > 0 Then
' Displays information in specified text boxes
Me.txtSessionMonth.Text = dsFind2.tblSessionID(0).SessionMonth.ToShortDateString()
Me.txtSessionType.Text = dsFind2.tblSessionID(0).SessionType.ToString
Me.txtSessionType.Text = dsFind2.tblSessionID(0).SessionType.ToString
Me.txtProgram.Text = dsFind2.tblSessionID(0).Program.ToString
Me.lblPilotEvaltrID.Text = dsFind2.tblSessionID(0).PilotEvaltrID.ToString
Me.lblSOEvaltrID.Text = dsFind2.tblSessionID(0).SOEvaltrID.ToString
Me.MinLevel.Text = dsFind2.tblSessionID(0).MinLevel.ToString
Me.IssCA.Checked = dsFind2.tblSessionID(0).IssuedCA.ToString
Me.IssFO.Checked = dsFind2.tblSessionID(0).IssuedFO.ToString
Me.IssSO.Checked = dsFind2.tblSessionID(0).IssuedSO.ToString
Me.txtFltNbr.Text = dsFind2.tblSessionID(0).FLTNbr.ToString()
Me.txtFltZDate.Text = dsFind2.tblSessionID(0).FltZDate.ToString
lblMessage.Text = ""
Else
lblMessage.Text = "No records were found!!"
End If
Catch ex As Exception
' Displays any error messages that may occur at runtime
lblMessage.Text = ex.Message
End Try
Can anyone offer me a solution?
Comment