SQL的数据库已经建好,ODBC也已经设好,如果想让VB中的程序与数据库连接,还要对VB进行什么设置?谢谢!顺便问一下,在数据库中建表、视图和过程是不是每个系统中必须有的?在创建存储过程时怎么修改文本中的内容呢?

解决方案 »

  1.   

    Public Cnn As New ADODB.Connection   '定义公共的数据连接对象
    Public Sub Main()
        On Error GoTo Err_Handle
        
        Dim strServer As String
        Dim strUserName As String
        Dim strPassword As String
     
        strServer = GetSetting("SoftName", "LoginInformation", "Server", "")
        strUserName = GetSetting("SoftName", "LoginInformation", "UserName", "")
        strPassword = GetSetting("SoftName", "LoginInformation", "Password", "")
       'Read Soft Name
        Set Cnn = New ADODB.Connection
            Cnn.CursorLocation = adUseClient
            Cnn.ConnectionString = "Provider=SQLOLEDB.1;Initial Catalog=Database;Password=" & Trim(strPassword) & ";Persist Security Info=true;User ID=" & trim(StrUserName) & ";Data Source=" & Trim(strServer)       
              Cnn.Open                                                                                          FrmMain.Show  '显示第一个主窗体
     
            Exit Sub
            
    Err_Handle:
        MsgBox Err.Description, vbInformation
        
    End Sub将这段代码写在模块中就可以调用了。
      

  2.   

    Dim con As ADODB.Connection
    Dim str As Stream
    str = "连接字符串"
    set con=new adodb.connection
    con.ConnectionString = str
    con.Open再声明一个adodb.recordset对象用于对记录操作