一个有关的数据库读取与转换的错误!
我在VB。NET模块里自定义了一个函数如下:
Public Function ReadOneValue(ByVal mySql As String)
Dim myConnection As SqlConnection = New SqlConnection(strConnect)
Dim myCommand As New SqlCommand(mySql, myConnection)
Dim Ad As SqlDataAdapter = New SqlDataAdapter()
Try
Ad.SelectCommand = myCommand
Dim ds As DataSet = New DataSet()
Ad.Fill(ds)
ReadOneValue = ds.Tables(0).Rows(0).Item(0)
myConnection.Close()
Catch e As System.IndexOutOfRangeException
Console.Write(e.ToString)
ReadOneValue = ""
End Try
End Function
然后我在VB的WEB窗体下调用
PAGE_LOAD过程
pubsql="一个SQL语句"
if ReadOneValue(pubsql)<>"" then '这句话提示DBNULL 无法强制转换为String DBNULL<>""
textbox1.text=ReadOneValue("pubsql ")
end if
请各位高手指点错误!