从system.double到system.byte[]的转换无效

stonecry 2007-07-02 03:01:33
我的程序里有这么一句:

dim dr as oledb.oledbdatareader

oledbcommand4.commandtext="select endtime-starttime as timelong from table where id in @id" '不是一样的,但就是这个意思

oledbcommand4.connection.open()

dr=oledbcommand4.excutereader

datagrid1.datasource=dr

datagrid1.databind()

''''''''''''''''''''''''''''''''''''''''

运行时提示 从system.double到system.byte[]的转换无效,

什么意思啊?如何解决??谢谢!!



...全文
296 19 打赏 收藏 转发到动态 举报
写回复
用AI写文章
19 条回复
切换为时间正序
请发表友善的回复…
发表回复
stonecry 2007-07-03
  • 打赏
  • 举报
回复
分分给了。

再次谢谢各位。
stonecry 2007-07-03
  • 打赏
  • 举报
回复
按第二种方法搞定,但是还是搞不懂第一种怎么不行。谢谢Bote_China
耶谢谢各位回帖。敬分。
stonecry 2007-07-03
  • 打赏
  • 举报
回复
晕了。我还是采用第一种方法,
提示我“@id变量未定义。。。。。
bote_china 2007-07-03
  • 打赏
  • 举报
回复
有更好的方法,把dr2的sql语句嵌套到oledbcommand4的Commandtext中,比如
select endtime-starttime as timelong from table where id in (select id from IdTable where ......)
bote_china 2007-07-03
  • 打赏
  • 举报
回复
oledbcommand4.commandtext="select endtime-starttime as timelong from table where id in (@id)"
dim p1 as oledb.oledbparameter
p1=new oledb.oledbparameter("@id",oledb.oledbtype.varchar)
dim pValue as string
while (dr2.read())
pValue &=dr2("id") & ","
end while
pValue = pValue.SubString(0,pValue.Length-1)
p1.value=pValue
oledbcommand4.parameters.add(p1)

stonecry 2007-07-03
  • 打赏
  • 举报
回复
楼上的大侠,我的idlist是动态获取的:
while (dr2.read())
idlist.add(dr2("id"))
end while
p1.value=idlist

bote_china 2007-07-03
  • 打赏
  • 举报
回复
oledbcommand4.commandtext="select endtime-starttime as timelong from table where id in (@id)"
dim p1 as oledb.oledbparameter
p1=new oledb.oledbparameter("@id",oledb.oledbtype.varchar)
p1.value=string.Join(",",new string() {11213,11215,11217})
oledbcommand4.parameters.add(p1)
foyuan 2007-07-02
  • 打赏
  • 举报
回复
前台用DataBind

<%# %>
Mydscn 2007-07-02
  • 打赏
  • 举报
回复
SELECT 语句 IN 后面是应该有()的

oledbcommand4.commandtext="select endtime-starttime as timelong from table where id in (11213,11215,11217)
stonecry 2007-07-02
  • 打赏
  • 举报
回复
我想了一下应该是@id的问题。

我是这么写的:
dim idlist as arraylist

dim p1 as oledb.oledbparameter

idlist =new arraylist

idlist.add(11213)

idlist.add(11215)

idlist.add(11217)

p1=new oledb.oledbparameter("@id",oledb.oledbtype.varbinary)

oledb.oledbparameter.add(p1)

p1.value=idlist

各位大侠,应该怎么该啊???
nic7968 2007-07-02
  • 打赏
  • 举报
回复
oledbcommand4.commandtext="select endtime-starttime as timelong from table where id in @id"

你这查询语句有问题吧。。。。
应该:
"select [endtime-starttime] as timelong from table where id in @id"
wzd24 2007-07-02
  • 打赏
  • 举报
回复
怀疑是@id的类型错误!
北京的雾霾天 2007-07-02
  • 打赏
  • 举报
回复
object obj = dr=oledbcommand4.ExcuteReader();

if (obj!=null)
{
Console.WriteLine(obj.GetType().Name);
}
这样查看一下这个obj是个什么东东
stonecry 2007-07-02
  • 打赏
  • 举报
回复
运行时,红色的是这句:

dr=oledbcommand4.excutereader
-过客- 2007-07-02
  • 打赏
  • 举报
回复
你数据库中的id 是什么类型的,你传进来的参数@id又是什么类型的,什么样的数据
stonecry 2007-07-02
  • 打赏
  • 举报
回复
好像跟datagrid1没关系吧,我去掉后面的绑定,不要datagrid1也是这么提示的,
jinpeng_dotnet 2007-07-02
  • 打赏
  • 举报
回复
小的能往大的转,但是大的不能往小的转。
北京的雾霾天 2007-07-02
  • 打赏
  • 举报
回复
只从上面的代码应该看不出哪里错了,
不过你可能是你的DataGrid上的数据格式设置有问题.
通者归来 2007-07-02
  • 打赏
  • 举报
回复
看看datagrid1有没有绑定字段?如果有字段的类型是什么?可能是系统自动强制转换出问题了

16,554

社区成员

发帖
与我相关
我的任务
社区描述
VB技术相关讨论,主要为经典vb,即VB6.0
社区管理员
  • VB.NET
  • 水哥阿乐
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧