一个类用vb写的  sql server2005数据库   具体功能是  当传入  select update insert delete这四种sql语句的时候,,会在把sql传入到数据库中执行  返回的结果可以   更新之后可以在datagridivew中显示
   
   就是datagrivew可以重新绑定数据源,,但是我不大会怎么做,,,一定要用VB啊先多谢了

解决方案 »

  1.   

    这个删除、插入、修改都可以Public Function ExecuteSQL(ByVal SQL As String) As ADODB.Recordset
        Dim cnn As New ADODB.Connection
        Dim rst As ADODB.Recordset
        Dim sTokens() As String
        
    On Error GoTo Error_Do    cnn.Open PublicStr
        sTokens() = Split(SQL)
        
        If InStr("INSERT,DELETE,UPDATE", UCase(sTokens(0))) Then
            cnn.Execute SQL
        Else
            Set rst = New ADODB.Recordset
            
            With rst
                .ActiveConnection = cnn
                .CursorLocation = adUseClient
                .CursorType = adOpenStatic
                .LockType = adLockOptimistic
                .Open Trim(SQL)
            End With
            Set ExecuteSQL = rst
        End If
        
        Set cnn = Nothing
        Set rst = Nothing
        Exit Function
    Error_Do:
        Dim Err_Str As String
        Err_Str = "服务器" & Err.Description
        If MsgBox(Err_Str, vbRetryCancel + vbCritical, "警告") = vbRetry Then
            Resume
        Else
            Set cnn = Nothing
            Set rst = Nothing
            End
        End If
    End Function