求源码(VB+MSSQL)希望哪位提供一个结构清晰, 有说明及注释的源代码.THANK YOU

解决方案 »

  1.   


    Public adoCN As New ADODB.Connection       '定义数据库的连接存放数据和代码Public SqlCommand As New ADODB.Command     '定义 SQL 命令Dim adoDateTime As New ADODB.Recordset     '获取 NT-SERVER 时间'***********************************************************************
    '*  功能:与 SQL SERVER 数据库建立连接并取出服务器时间
    '***********************************************************************
    Public Function OpenConnection() As String '打开数据库
        On Error GoTo SQLConErr
        With adoCN
            .CursorLocation = adUseClient
            .Provider = "sqloledb"
            .Properties("Data Source").Value = cNtServerName
            .Properties("Initial Catalog").Value = cDatabaseName
            .Properties("User ID") = cSQLUserName
            .Properties("Password") = cSQLPassword
            .Properties("prompt") = adPromptNever
            .ConnectionTimeout = 15  ‘可以改这个时间
            .Open
            
            If .State = adStateOpen Then
                adoDateTime.Open "select getdate()", adoCN, adOpenStatic, adLockOptimistic
                cServerDate = Format(adoDateTime(0), "yyyy-mm-dd")
                cServertime = Mid(adoDateTime(0), 10)
            Else
                MsgBox "数据库连接失败,请找系统管理员进行检查 !", 16, cProgramName
                End
            End If
        End With
        
        SqlCommand.ActiveConnection = adoCN
        SqlCommand.CommandType = adCmdText
        Exit Function
    SQLConErr:
        Select Case Err.Number
            Case -2147467259
                MsgBox "找不到指定的SQL Server服务器或者数据库不存在,请重新设置!", vbExclamation
                F_SetSystem.Show 1
            Case -2147217843
                MsgBox "指定的SQL Server数据库用户不存在或口令错误,请重新设置!", vbExclamation
                F_SetSystem.Show 1
            Case Else
                MsgBox "数据环境连接失败,请找系统管理员进行检查 !", 16, cProgramName
        End Select
        OpenConnection
    End Function
      

  2.   


    Public adoCN As New ADODB.Connection       '定义数据库的连接存放数据和代码Public SqlCommand As New ADODB.Command     '定义 SQL 命令Dim adoDateTime As New ADODB.Recordset     '获取 NT-SERVER 时间'***********************************************************************
    '*  功能:与 SQL SERVER 数据库建立连接并取出服务器时间
    '***********************************************************************
    Public Function OpenConnection() As String '打开数据库
        On Error GoTo SQLConErr
        With adoCN
            .CursorLocation = adUseClient
            .Provider = "sqloledb"
            .Properties("Data Source").Value = cNtServerName
            .Properties("Initial Catalog").Value = cDatabaseName
            .Properties("User ID") = cSQLUserName
            .Properties("Password") = cSQLPassword
            .Properties("prompt") = adPromptNever
            .ConnectionTimeout = 15  ‘可以改这个时间
            .Open
            
            If .State = adStateOpen Then
                adoDateTime.Open "select getdate()", adoCN, adOpenStatic, adLockOptimistic
                cServerDate = Format(adoDateTime(0), "yyyy-mm-dd")
                cServertime = Mid(adoDateTime(0), 10)
            Else
                MsgBox "数据库连接失败,请找系统管理员进行检查 !", 16, cProgramName
                End
            End If
        End With
        
        SqlCommand.ActiveConnection = adoCN
        SqlCommand.CommandType = adCmdText
        Exit Function
    SQLConErr:
        Select Case Err.Number
            Case -2147467259
                MsgBox "找不到指定的SQL Server服务器或者数据库不存在,请重新设置!", vbExclamation
                F_SetSystem.Show 1
            Case -2147217843
                MsgBox "指定的SQL Server数据库用户不存在或口令错误,请重新设置!", vbExclamation
                F_SetSystem.Show 1
            Case Else
                MsgBox "数据环境连接失败,请找系统管理员进行检查 !", 16, cProgramName
        End Select
        OpenConnection
    End Function
      

  3.   

    Dim rstTitles As ADODB.Recordset
       Dim strCnn As String
       Dim strTitle As String
       Dim strMessage As String   ' Assign connection string to variable.
          strCnn = "Provider=sqloledb;" & _
          "Data Source=srv;Initial Catalog=pubs;User Id=sa;Password=; "   Set rstTitles = New ADODB.Recordset
       rstTitles.CursorType = adOpenKeyset
       rstTitles.LockType = adLockBatchOptimistic
       rstTitles.Open "titles", strCnn, , , adCmdTable
       
       rstTitles.MoveFirst   ' Loop through recordset, and prompt user for 
       ' change of type for a specified title.
       Do Until rstTitles.EOF
          If Trim(rstTitles!Type) = "psychology" Then
             strTitle = rstTitles!Title
             strMessage = "Title: " & strTitle & vbCr & _
                "Change type to self help?"         If MsgBox(strMessage, vbYesNo) = vbYes Then
                rstTitles!Type = "self_help"
             End If
          End If      rstTitles.MoveNext
       Loop   ' Ask if the user wants to commit to all the 
       ' changes made earlier.
       If MsgBox("Save all changes?", vbYesNo) = vbYes Then
          rstTitles.UpdateBatch
       Else
          rstTitles.CancelBatch
       End If   ' Print current data in recordset.
       rstTitles.Requery
       rstTitles.MoveFirst
       Do While Not rstTitles.EOF
          Debug.Print rstTitles!Title & " - " & rstTitles!Type
          rstTitles.MoveNext
       Loop   ' Restore original values because this is a demonstration.
       rstTitles.MoveFirst
       Do Until rstTitles.EOF
          If Trim(rstTitles!Type) = "self_help" Then
             rstTitles!Type = "psychology"
          End If
          rstTitles.MoveNext
       Loop
       rstTitles.UpdateBatch   rstTitles.Close
      

  4.   

    http://www.dapha.net/down/show.asp?classid=1&Nclassid=111
      

  5.   

    cn.ConnectionString = "Driver={MySQL ODBC 3.51 Driver};Option=3;port=3306;stmt=;DSN=;SRVR=orient-zgq;DB=orientnbcws;UID=root;PWD="
      

  6.   

    Public Function havedatasourse4(sqlpwd As String, sqlusr As String) As Boolean 
       On Error GoTo dsmsg
            Set adoconlocal = New ADODB.Connection '打开数据库
            sql = "Provider=SQLOLEDB.1;User ID=" & sqlusr & ";password=" & sqlpwd & ";Initial Catalog=master;Data Source=localhost"        adoconlocal.ConnectionTimeout = 10
            adoconlocal.Open sql
            havedatasourse4 = True
       
      
       Exit Function
    dsmsg:
          havedatasourse4 = False
    End Function
      

  7.   


    工程--->引用--->Microsoft ActiveX Data Object 2.x(版本号)    Dim CN   As New ADODB.Connection                '定义数据库的连接
        Dim Rs   As New ADODB.Recordset
        CN.ConnectionString = "Provider=sqloledb;Data Source=pmserver;Initial Catalog=northwind;User Id=sa;Password=sa;"    CN.Open
        Rs.CursorLocation = adUseClient
        Rs.Open "select * from employees", CN, adOpenDynamic, adLockOptimistic
       Set DataGrid1.DataSource = Rs
      

  8.   

    各位:好,谢谢各位的热情!请推荐一个好一点以VB+MSSQL结构的源代码, 最近是一套的, 结构清晰!谢谢
      

  9.   

    来信:[email protected],来信注明VB+MSSQL源代码
      

  10.   

    来信:[email protected],来信注明VB+MSSQL源代码