2009-12-07 209 views

回答

1

found this as an example - 我还没有尝试过自己知道100%肯定,如果它工作或没有,我也不自称自己是一个vb.net程序员,但它至少一些尝试......

Imports System.Data 
Imports Microsoft.Data.Odbc 

' Database Connection 
Public dbConn As OdbcConnection = Nothing 
Public dbCmnd As OdbcCommand 
Public dbReader As OdbcDataReader 
Public dbConnStr As String 
Public dbError As Exception 

' Connect to MAS90 using ODBC; dbError stores the 
' exception if any 
Sub connectToDatabase(ByVal company As String, ByVal uid As String, ByVal pwd As String) 

    Dim dsn As String = "SOTAMAS90" 
    Dim timeout As String = "360" 

    ' Build the connection string 
    dbConnStr = "DSN=" + dsn + _ 
      ";Directory=M:\MAS90" + _ 
      ";Prefix=M:\MAS90\soa\" + _ 
      ";ViewDLL=M:\MAS90\Home\" + _ 
      ";SERVER=NotTheServer" + _ 
      ";Company=" + company + _ 
      ";UID=" + uid + ";PWD=" + pwd + ";" 

    ' Connect if not already 
    If (dbConn Is Nothing) Then 
     Try 
      dbConn = New OdbcConnection(dbConnStr) 
      dbConn.ConnectionTimeout = timeout 
      dbConn.Open() 
      dbError = Nothing 
     Catch ex As Exception 
      dbError = ex 
      dbConn = Nothing 
     End Try 
    End If 
End Sub