类型:转载 责任编辑:asp.net 日期:2007/05/23
热门软件下载:
帮我写了一个函数 用来检查表中是否存在某条记录
存在返回真,不存在假.
我写的老是提示什么类型 DBNull 无法转换 到 integer
哪里错了,
Public Function Exist(ByVal strSql As String) As Boolean
//注: strsql="select * from customers where id=00001"
Dim myCmd As New OleDbCommand
Try
myCmd.CommandText = strSql
myCmd.Connection = cn
myCmd.CommandType = CommandType.Text
If myCmd.ExecuteNonQuery Then
Return True
Else
Return False
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
myCmd.dispose()
End Try
End Function
网友回答:
Public Function Exist(ByVal strSql As String) As Boolean
strsql="select count(id) from customers where id=00001"
Dim myCmd As New OleDbCommand
Try
myCmd.CommandText = strSql
myCmd.Connection = cn
myCmd.CommandType = CommandType.Text
dim intC as integer=Convert.ToInt32(objCmd.ExecuteScalar())
If intC=0 Then
Return false
Else
Return true
End If
Catch ex As Exception
MsgBox(ex.ToString)
Finally
myCmd.dispose()
End Try
End Function