标题:如何处理SQL查询返回空值的问题,求助!
只看楼主
mkb21
Rank: 1
等 级:新手上路
帖 子:30
专家分:0
注 册:2007-9-22
 问题点数:0 回复次数:1 
如何处理SQL查询返回空值的问题,求助!
WinFrm过程代码:
    public myItem as String    '用于返回值的公共变量
    Public Sub DatSearch(ByVal TabName As String, ByVal Field As String, ByVal Guide As String)
        CmdText = "Select " & Field & " From " & TabName & " Where " & Guide
        If Conn.State = 1 Then Conn.Close()
        Dim Cmd As SqlClient.SqlCommand = New SqlClient.SqlCommand(CmdText, Conn)
        SQLAdp.SelectCommand = New SqlClient.SqlCommand(CmdText, Conn)
        Try
            Conn.Open()
            SQLAdp.Fill(DataSet, "SearchTab")
            Dim myResp As Object = Cmd.ExecuteScalar         '判断是否存在记录
            myItem = IIf(myResp Is System.DBNull.Value, Nothing, DataSet.Tables("SearchTab").Rows(0).Item(0))
            DataSet.Tables("SearchTab").Clear()
            DataSet.Tables.Remove("SearchTab")
            Conn.Close()
        Catch ex As Exception
            MsgBox(ex.Message)
            Exit Try
        End Try
    End Sub
当查询返回空记录时,会出错:“在0处没有任何行!”
怎样才能处理出现空值或空记录的情况,谢谢高手指点!
搜索更多相关主题的帖子: SQL Conn String 
2008-05-13 16:30
happynight
Rank: 8Rank: 8
等 级:贵宾
威 望:15
帖 子:807
专家分:760
注 册:2008-4-26
得分:0 
发错了 应发论坛
2008-05-13 17:04



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-214100-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.244227 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved