Option Explicit
Private Sub Command1_Click()
Dim objcnn As ADODB.Connection
Dim strTmp As String
Dim objRst As New ADODB.Recordset
Dim strsql As String
Set objcnn = New ADODB.Connection
With objcnn
.ConnectionString = "Provider=sqlOLEDB;Data source=192.168.8.249;Database=PA;Uid=sa;Pwd=kicpassword"
.Open
End With
'FTimeStamp 为timestamp类型的字段
objRst.Open "Select Top 1 FTimeStamp From M_Batch01",objcnn,adOpenStatic,adLockReadOnly
If Not objRst.EOF Then
'先取得查询到的时间戳
strTmp = TimestampToString(objRst.Fields("FTimeStamp"))
MsgBox strTmp
'进行更新,注意更新条件里加了时间戳(主要用来处理并发使用,防止更新的时候记录被其他用户修改)
strsql = "Update m_batch01 set IsExportToK='Y' Where batchid=1882 and FTimeStamp=" & strTmp
objcnn.Execute strsql
MsgBox "OK"
End If
End Sub
'转换函数 Private Function TimestampToString(RsCol As ADODB.Field) As String Dim Buffer As String Dim i As Integer Buffer = "0x" For i = 1 To 8 Buffer = Buffer & Right("00" & Hex(AscB(MidB(RsCol,i,1))),2) Next i TimestampToString = Buffer End Function
原文链接:https://www.f2er.com/vb/259467.html