本文介绍了"演员QUOT; .aspx页面中的VB代码错误,扭曲...的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误因此:从类型''DBNull''转换为''String''类型无效。

简单,对吧?好吧,没有(或者至少不适合我)。


这是一个函数,后跟下面的调用代码:


函数GetDetails(ByVal x As String,ByVal y as String)

Dim conn As New SqlConnection

(" server = localhost; uid = blah; pwd = blah; database =测试")

Dim strSQL As String

Dim ds作为新数据集()


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")

返回ds.Tables(" firstv")

结束功能


来电代码:


< asp :DataGrid runat = server id = dgDetails

DataSource =<%#

GetDetails(container.dataitem(" doc")),container.dat aitem(" 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:DataGrid>

错误发生在第一个上面调用代码的行。

当然,我想啊,它必须从doc中取出空值并且在firstv中输入
po字段,这必须是引起"。所以我打开了Query

Analyzer并将所有空值(在每一列中)更改为空白。还是

得到了错误所以我回到QA并将它们全部更改为xyz。

仍然,我收到了错误!我想也许它与函数中的ByVal

语句有关,并切换到ByRef ...仍然没有去。任何人

有什么提示吗?

谢谢!是的,我仍然是.NET的新手。 ;)

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:DataGrid runat=server id=dgDetails
DataSource=<%#
GetDetails(container.dataitem("doc"),container.dat aitem("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:DataGrid>
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. ;)

推荐答案





这篇关于&QUOT;演员QUOT; .aspx页面中的VB代码错误,扭曲...的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-15 00:15