求助!辛苦了!
我要一个VB例子,查询一个SQL语句,只要返回是否有匹配的内容?(不要存储过程access数据库)
辛苦了~~~先感谢了!
[67 byte] By [
chhlyy] at [2008-1-9]
Shared Function selsql(ByRef sql As String) As Boolean
Dim b As Boolean = False
Dim conn As New OleDbConnection
Dim cmd As New OleDbCommand()
conn.ConnectionString = ConfigurationManager.ConnectionStrings("AccessConn").ConnectionString
Dim reader As OleDbDataReader
Dim previousConnectionState As ConnectionState = conn.State
cmd.Connection = conn
cmd.CommandText = sql
conn.Open()
Try
If conn.State = ConnectionState.Closed Then
conn.Open()
End If
reader = cmd.ExecuteReader()
Using reader
While reader.Read()
If reader.Item(0).ToString() > 0 Then
b = True
End If
End While
End Using
Catch ex As Exception
Finally
If previousConnectionState = ConnectionState.Closed Then
conn.Close()
End If
End Try
Return b
End Function
是不是要这样的