Dim sqlConnection1 As SqlClient.SqlConnection
Dim strConnect As String="data source=服务器名;initial catalog=数据库名;user id=sa;password=;"
sqlConnection1=New SqlClient.SqlConnection(strConnect)
try
sqlConnection1.open ‘打开数据库
msgbox("OK")
sqlConnection1.close ‘关闭连接,释放资源
catch ex As exception
msgBox(ex.message)
end try
###################或者
Public CNN As New ADODB.Connection
Public GclsReaderGroup As New GzReader
Public GstrMealCardReaderTabOption As String
Sub Main()
Dim strCnn As String
strCnn = "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=DasIcCard;Data Source=(Local)"
CNN.ConnectionString = strCnn
CNN.CursorLocation = adUseClient
CNN.Open
frmMain.Show
End Sub
'Get the CardID
Public Function GetCardID(ByVal PressworkID As String, ByVal EmpName As String) As Long
On Error GoTo Myerror
Dim strSQL As String
Dim rs As New ADODB.Recordset
Dim CardID As Long
strSQL = "select cCard.CardID From cCard inner join cEmployee on cCard.CardID=cEmployee.MainCardID"
strSQL = strSQL & " where cCard.PressWorkID='" & Trim(PressworkID) & "' and cEmployee.EmployeeName='" & Trim(EmpName) & "'"
Set rs = CNN.Execute(strSQL)
CardID = rs.Fields(0).value
GetCardID = CardID
Set rs = Nothing
Exit Function
Myerror:
MsgBox Err.Description
GetCardID = 0
Resume Next