查看: 1041|回复: 17
|
空白的field.... (asp.net + mysql)
[复制链接]
|
|
我的 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 |
|
|
|
|
|
|
|

楼主 |
发表于 9-6-2006 07:36 PM
|
显示全部楼层
|
|
|
|
|
|
|
发表于 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 编辑 ] |
|
|
|
|
|
|
|
发表于 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!! |
|
|
|
|
|
|
|
发表于 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
|
显示全部楼层
|
|
|
|
|
|
|
发表于 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 编辑 ] |
|
|
|
|
|
|
|

楼主 |
发表于 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
|
显示全部楼层
|
|
|
|
|
|
| |
本周最热论坛帖子
|