"演员QUOT; .aspx页面中的VB代码错误,扭曲... [英] "Cast" error with VB code in .aspx page, with a twist...

查看:54
本文介绍了"演员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. ;)

推荐答案

如果您确定没有空值,我不确定我是否有答案

来自你的sql。这可能只是下次你的提示

然后。这是我下次写这个声明的方式;

我想消除snulls作为一个问题。


strSQL =" SELECT IsNull(firstv.ocean_car,'''') ,IsNull(firstv.nr,

''''),IsNull(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


克里斯


< ro ********** @ gmail.com>在消息中写道

news:11 ********************** @ f14g2000cwb.googlegr oups.com ...
I am not sure that I have an answer for you if your sure there are no nulls
coming through your sql. This may be just a hint for next time for you
then. This is how I would write the statement next time; at least I do when
I want to eliminate snulls as an issue.

strSQL = "SELECT IsNull(firstv.ocean_car, ''''), IsNull(firstv.nr,
''''),IsNull(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

Chris

<ro**********@gmail.com> wrote in message
news:11**********************@f14g2000cwb.googlegr oups.com...
因此错误:从类型''DBNull''转换为''String''类型无效。
简单,对吧?好吧,没有(或者至少不适合我)。

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

函数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")
返回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>

错误发生在上面调用代码的第一行。
当然,我想 ;啊,它必须从firstv中的doc和
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. ;)



嘿Chris,


感谢您的输入。在绝望中,我把你的代码放在我的地方

。同一行上的错误相同。 *叹气*

Hey Chris,

Thanks for the input. In sheer desperation I popped your code there in
place of mine. Same error on the same line. *sigh*


实际上...我发生了其他事情。这个错误可能是一个红色的鲱鱼吗?如在,假设x或x。或y或y。包含空白数据,

可以加入或sql语句的一部分(在函数内)

导致强制转换错误?


编译器会将空的x或y值识别为'''或....?

任何人都知道编译器会如何解释在这种情况下空白?

Actually... something else occurred to me. Could the error perhaps be a
red herring? As in, assuming either "x" or "y" contained blank data,
could the join or where part of the sql statement (within the function)
be causing the "cast" error?

Would the compiler recognize the empty x or y values as '''' or ....?
Anyone know how the compiler would interpret blanks in this case?


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

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆