远程访问sqlserver
Dim objRS As ADODB.Recordset
Dim objCon As ADODB.Connection
Dim getConString As String 'Variable for the connectionstring
Dim sqlProvider As String
Set objCon = New ADODB.Connection
Set objRS = New ADODB.Recordset
getConString = "Provider=SQLOLEDB.1" & _
";Persist Security Info=False" & _
";User ID=用户名" & _
";Password=密码" & _
";Initial Catalog=sqlserver数据库名" & _
";Data Source=服务器名或IP" & _
";Network Library=DBMSSOCN"
GetCon
GetRecordSet ("sql语句")
Private Sub GetCon()
If objCon.State = adStateOpen Then objCon.CloseWith objCon
.ConnectionString = getConString
.Open
End With
End Sub
Sub GetRecordSet(strSource As String)
If objRS.State = adStateOpen Then objRS.Close 'If the database is open close before getting a new recordset
'On Error GoTo Errorhandler 'I take care of eventual errorsSelect Case bolEditReadRS 'Tells which kind of recordset to get
Case False
With objRS
.ActiveConnection = objCon
.CursorLocation = adUseClient
.CursorType = adOpenKeyset 'Move the cursor in any direction and bookable
.LockType = adLockReadOnly 'Editing is not possible
.Source = strSource 'What Recordset to get
.Open
.MoveFirst
End With
Case True
With objRS
.ActiveConnection = objCon
.CursorLocation = adUseClient
.CursorType = adOpenKeyset 'Move the cursor in any direction and bookable
.LockType = adLockOptimistic 'Editing is possible
.Source = strSource 'What Recordset to get
.Open
.MoveFirst
End With
End Select
End Sub
7.怎样把数字转换成二进制数字
Public Function convDecToBin(ByVal curNumber As Currency) As String
On Error GoTo convDecToBin_end
Dim strBin As String
Dim i As Long For i = 64 To 0 Step -1 If Int(curNumber / (2 ^ i)) = 1 Then strBin = strBin & "1"
curNumber = curNumber - (2 ^ i) Else If strBin <> "" Then
strBin = strBin & "0"
End If End If Next convDecToBin = strBinconvDecToBin_end:
If Err <> 0 Or strBin = "" Then convDecToBin = "-E-"
Exit Function
End Function
Dim objRS As ADODB.Recordset
Dim objCon As ADODB.Connection
Dim getConString As String 'Variable for the connectionstring
Dim sqlProvider As String
Set objCon = New ADODB.Connection
Set objRS = New ADODB.Recordset
getConString = "Provider=SQLOLEDB.1" & _
";Persist Security Info=False" & _
";User ID=用户名" & _
";Password=密码" & _
";Initial Catalog=sqlserver数据库名" & _
";Data Source=服务器名或IP" & _
";Network Library=DBMSSOCN"
GetCon
GetRecordSet ("sql语句")
Private Sub GetCon()
If objCon.State = adStateOpen Then objCon.CloseWith objCon
.ConnectionString = getConString
.Open
End With
End Sub
Sub GetRecordSet(strSource As String)
If objRS.State = adStateOpen Then objRS.Close 'If the database is open close before getting a new recordset
'On Error GoTo Errorhandler 'I take care of eventual errorsSelect Case bolEditReadRS 'Tells which kind of recordset to get
Case False
With objRS
.ActiveConnection = objCon
.CursorLocation = adUseClient
.CursorType = adOpenKeyset 'Move the cursor in any direction and bookable
.LockType = adLockReadOnly 'Editing is not possible
.Source = strSource 'What Recordset to get
.Open
.MoveFirst
End With
Case True
With objRS
.ActiveConnection = objCon
.CursorLocation = adUseClient
.CursorType = adOpenKeyset 'Move the cursor in any direction and bookable
.LockType = adLockOptimistic 'Editing is possible
.Source = strSource 'What Recordset to get
.Open
.MoveFirst
End With
End Select
End Sub
7.怎样把数字转换成二进制数字
Public Function convDecToBin(ByVal curNumber As Currency) As String
On Error GoTo convDecToBin_end
Dim strBin As String
Dim i As Long For i = 64 To 0 Step -1 If Int(curNumber / (2 ^ i)) = 1 Then strBin = strBin & "1"
curNumber = curNumber - (2 ^ i) Else If strBin <> "" Then
strBin = strBin & "0"
End If End If Next convDecToBin = strBinconvDecToBin_end:
If Err <> 0 Or strBin = "" Then convDecToBin = "-E-"
Exit Function
End Function
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货