佳礼资讯网

 找回密码
 注册

ADVERTISEMENT

查看: 1042|回复: 17

空白的field.... (asp.net + mysql)

[复制链接]
发表于 9-6-2006 04:34 PM | 显示全部楼层 |阅读模式
我的 user_table ( ID, name , address ) 里,address这个field是没有资料的

1, khoo,
2, kit,  johor
3, yuki, Seremban

当我select ID, address from user_table WHERE name = 'khoo'时,error就出来了!

While cmdreader.Read

      ID = cmdreader("ID")

      If Not cmdreader.IsDBNull("address") Then
             address = cmdreader("address")
      Else
             address = "-"
      End If

End While
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 9-6-2006 07:36 PM | 显示全部楼层
NO - DATA

有什么办法吗?
回复

使用道具 举报

发表于 9-6-2006 11:19 PM | 显示全部楼层
不太明白你的问题? 你的 asp.net error message 就只有 "No Data"?
回复

使用道具 举报

发表于 10-6-2006 08:17 AM | 显示全部楼层
当我在vs.net的command window做checking时

?cmdreader("address")

Run-time exception thrown : System.Data.Odbc.OdbcException - NO_DATA - no error information available

我相信这是因为在address这个field里contain no data...

我要如何防止error发生,但又不能避免address这个field contain no data(null)?
回复

使用道具 举报

发表于 11-6-2006 03:18 AM | 显示全部楼层
我假设你的 cmdreader 是 ODBCDataReader, 尝试改成:

If Not cmdreader.IsDBNull(2) Then
  address = cmdreader.GetString(2)
回复

使用道具 举报

 楼主| 发表于 11-6-2006 09:48 AM | 显示全部楼层
我的确是用ODBCDataReader, 但是同样的error还是出现!!

?cmdreader.IsDBNull(2)

Run-time exception thrown : System.Data.Odbc.OdbcException - NO_DATA - no error information available


my code as below

If Not cmdreader.IsDBNull(2) Then
   address = cmdreader.GetString(2)
Else
   address = ""
End If

注:基于一些原因。。 有些fields是会contain no data的...

[ 本帖最后由 一只优雅的猪 于 11-6-2006 10:36 AM 编辑 ]
回复

使用道具 举报

Follow Us
发表于 11-6-2006 02:31 PM | 显示全部楼层
原帖由 一只优雅的猪 于 11-6-2006 09:48 AM 发表
我的确是用ODBCDataReader, 但是同样的error还是出现!!

?cmdreader.IsDBNull(2)

Run-time exception thrown : System.Data.Odbc.OdbcException - NO_DATA - no error information available

my code a ...


对不起, 看了你的 select code, 你应该这样放:

If Not cmdreader.IsDBNull(1) Then
   address = cmdreader.GetString(1)
Else
   address = ""
End If

如果你有检查 .Net 的 manual, 你就会知道 IsDBNull 的 input parameter 不是 string, 而是你的 column index.
回复

使用道具 举报

 楼主| 发表于 11-6-2006 03:05 PM | 显示全部楼层
即使我改了,但无论是哪一个filed,只要是contain NO-DATA, 就会出现

Run-time exception thrown : System.Data.Odbc.OdbcException - NO_DATA - no error information available

?cmdreader.IsDBNull(1) = false
?cmdreader.IsDBNull(2) = false
?cmdreader.IsDBNull(3) = error!!
回复

使用道具 举报


ADVERTISEMENT

发表于 11-6-2006 03:27 PM | 显示全部楼层
首先我得问你

1. 你的 sql 怎么写?
2. IsDBNull 是怎么用的?
回复

使用道具 举报

 楼主| 发表于 11-6-2006 03:49 PM | 显示全部楼层
我的sql statement = "SELECT name , address FROM customer"

               
If Not cmdreader.IsDBNull(0) Then
    name = cmdreader.GetString(0)
Else
    name = ""
End If

If Not cmdreader.IsDBNull(1) Then
    address = cmdreader.GetString(1)
Else
    address = ""
End If
回复

使用道具 举报

发表于 11-6-2006 04:42 PM | 显示全部楼层
既然你只是在 sql 里选择 name, address, 那么你的 column index 只有 0, 和 1, 而 IsDBNull 就只是接受你仅有的 column index.
回复

使用道具 举报

 楼主| 发表于 11-6-2006 04:51 PM | 显示全部楼层
对啊。。 但为何error还是出现呢?

当address contain no data时,就出error了.....如果contain data就没问题

for example... address contact no data!!

?cmdreader.IsDBNull(1)

Run-time exception thrown : System.Data.Odbc.OdbcException - NO_DATA - no error information available
回复

使用道具 举报

 楼主| 发表于 12-6-2006 11:16 PM | 显示全部楼层
这个问题困扰我很久了,没有人可以给我建议吗?
回复

使用道具 举报

发表于 13-6-2006 04:24 PM | 显示全部楼层
原帖由 一只优雅的猪 于 12-6-2006 11:16 PM 发表
这个问题困扰我很久了,没有人可以给我建议吗?


试试看 if not cmdreader("address') is nothing then...
回复

使用道具 举报

 楼主| 发表于 13-6-2006 05:15 PM | 显示全部楼层
tried oledi... cannot ar
回复

使用道具 举报

发表于 13-6-2006 06:18 PM | 显示全部楼层
原帖由 一只优雅的猪 于 13-6-2006 05:15 PM 发表
tried oledi... cannot ar


If not cmdreader("address') Is DBNull.Value Then

这个leh???

[ 本帖最后由 小妞儿 于 13-6-2006 06:20 PM 编辑 ]
回复

使用道具 举报


ADVERTISEMENT

 楼主| 发表于 13-6-2006 11:35 PM | 显示全部楼层
to : 小妞儿

If not cmdreader("address') Is DBNull.Value Then
i tried oledi.. but the result is same!!

I even try to change "NOT NULL" to "NULL" in the database structure!

i tried the following method also.. but the result still the same

Try
      If Not cmdreader.IsDBNull(1) Then
          HttpContext.Current.Session("address") = cmdreader.GetString(1)
      End If
         
Catch ex As System.Data.Odbc.OdbcException
           HttpContext.Current.Session("address") = ""   
End Try
回复

使用道具 举报

发表于 13-6-2006 11:47 PM | 显示全部楼层
read this... this may be the cause of all the problems...

http://support.microsoft.com/default.aspx?scid=kb;EN-US;q319243
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

 

ADVERTISEMENT



ADVERTISEMENT



ADVERTISEMENT

ADVERTISEMENT


版权所有 © 1996-2023 Cari Internet Sdn Bhd (483575-W)|IPSERVERONE 提供云主机|广告刊登|关于我们|私隐权|免控|投诉|联络|脸书|佳礼资讯网

GMT+8, 22-8-2025 01:42 PM , Processed in 0.150944 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

快速回复 返回顶部 返回列表