R
roy.anderson
Error is thus: "Cast from type 'DBNull' to type 'String' is not valid."
Simple, right? Well, no (or at least not for me).
Here's a function, followed by the calling code below:
Function GetDetails(ByVal x As String, ByVal y as String)
Dim conn As New SqlConnection
("server=localhost;uid=blah;pwd=blah;database=test")
Dim strSQL As String
Dim ds As New DataSet()
strSQL = "SELECT firstv.ocean_car, firstv.nr,firstv.equip "
strSQL &= "FROM firstv INNER JOIN "
strSQL &= "lla ON firstv.doc + firstv.po = lla.doc + lla.po "
strSQL &= "WHERE firstv.doc = " & x & "AND firstv.po = " & y
Dim da As New SqlDataAdapter(strSQL, conn)
da.Fill(ds, "firstv")
Return ds.Tables("firstv")
End Function
Calling code:
<asp
ataGrid runat=server id=dgDetails
DataSource=<%#
GetDetails(container.dataitem("doc"),container.dataitem("po"))%>
AutoGenerateColumns=false>
<Columns>
<asp:BoundColumn DataField="ocean_car"
HeaderText="Carrier"></asp:BoundColumn>
<asp:BoundColumn DataField="nr" HeaderText="Booking"></asp:BoundColumn>
<asp:BoundColumn DataField="Equip"
HeaderText="Equip"></asp:BoundColumn>
</Columns>
</asp
ataGrid>
The error occurs on the very first line of the calling code above.
Naturally, I thought "ah, it must be pulling in nulls from the doc and
po fields in firstv and that must be the cause." So I opened Query
Analyzer and changed all the nulls (in every column) into blanks. Still
got the error so I went back to QA and changed them all to "xyz."
Still, I got the error!! I thought maybe it had to do with the "ByVal"
statement in the function and switched to ByRef... still no go. Anyone
have any tips, please?
Thanks! And yes, I am still am relatively new to .NET.
Simple, right? Well, no (or at least not for me).
Here's a function, followed by the calling code below:
Function GetDetails(ByVal x As String, ByVal y as String)
Dim conn As New SqlConnection
("server=localhost;uid=blah;pwd=blah;database=test")
Dim strSQL As String
Dim ds As New DataSet()
strSQL = "SELECT firstv.ocean_car, firstv.nr,firstv.equip "
strSQL &= "FROM firstv INNER JOIN "
strSQL &= "lla ON firstv.doc + firstv.po = lla.doc + lla.po "
strSQL &= "WHERE firstv.doc = " & x & "AND firstv.po = " & y
Dim da As New SqlDataAdapter(strSQL, conn)
da.Fill(ds, "firstv")
Return ds.Tables("firstv")
End Function
Calling code:
<asp

DataSource=<%#
GetDetails(container.dataitem("doc"),container.dataitem("po"))%>
AutoGenerateColumns=false>
<Columns>
<asp:BoundColumn DataField="ocean_car"
HeaderText="Carrier"></asp:BoundColumn>
<asp:BoundColumn DataField="nr" HeaderText="Booking"></asp:BoundColumn>
<asp:BoundColumn DataField="Equip"
HeaderText="Equip"></asp:BoundColumn>
</Columns>
</asp

The error occurs on the very first line of the calling code above.
Naturally, I thought "ah, it must be pulling in nulls from the doc and
po fields in firstv and that must be the cause." So I opened Query
Analyzer and changed all the nulls (in every column) into blanks. Still
got the error so I went back to QA and changed them all to "xyz."
Still, I got the error!! I thought maybe it had to do with the "ByVal"
statement in the function and switched to ByRef... still no go. Anyone
have any tips, please?
Thanks! And yes, I am still am relatively new to .NET.
