Home > Software engineering > VB WINSOCK client article how to obtain SQL returns the record number?
VB WINSOCK client article how to obtain SQL returns the record number?
Time:09-19
'Option Explicit' WINSOCK client code Private Declare Sub CopyMemory Lib "kernel32" Alias "RtlMoveMemory" (Destination As Byte, Source As Byte, ByVal Length As Long) Dim strSQL As String
Private Sub Command1_Click () If sockClient. State & lt;> SckClosed Then sockClient. Close If txtServerName. Text & lt;> VbNullString Then SockClient. RemoteHost=txtServerName. Text 'set up a remote computer name The Else MsgBox "must enter the server name or IP address," vbInformation, "tip" The Exit Sub End the If If txtServerPort. Text & lt;> VbNullString Then SockClient. RemotePort=txtServerPort. Text 'set up a remote port name The Else MsgBox "must enter remote port", vbInformation, "tip" The Exit Sub End the If SockClient. Protocol=sckTCPProtocol 'set the Winsock control Protocol is used by the TCP, SockClient. Connect 'request to Connect to the remote computer Me. Label3. Caption="connected" End Sub
Private Sub Command2_Click () StrSQL=Me. Text1. Text If sockClient. State=sckConnected Then SockClient. SendData publishes the event strSQL DoEvents End the If End Sub
Private Sub Form_Load () Me. Label3. Caption="not connected" TxtServerName. Text="112.74.36.215" Text1. Text="QFII815, select TOP 500 * from BillIndex" 'QFII815 is the database name End Sub
Private Sub sockClient_DataArrival (ByVal bytesTotal As Long) Dim tmpData () As Byte Dim Finis As String, FinisData end (3) As Byte 'access sign The Static rsLength As Long The Static iCount the As Integer The Static rsData () As Byte 'records for several group Dim arrData () As Byte Dim objRec As you SockClient. GetData tmpData, vbArray + vbByte 'the received data stored in rsData If iCount=0 Then 'first receive RsData=https://bbs.csdn.net/topics/tmpData ICount=1 The Else ReDim Preserve rsData (rsLength + bytesTotal) CopyMemory rsData (rsLength + 1), tmpData (0), bytesTotal End the If RsLength=UBound (rsData) 'rsData length CopyMemory FinisData (0), rsData (rsLength - 3), 4 Finis=FinisData If Finis="`!" Then 'if is the end, end truncation symbol data ReDim Preserve tmpData (rsLength - 4) The Set objRec=BinToRs (rsData) 'reduction recordset Set MSHFlexGrid1. The DataSource=objRec 'data' client table shows is a success Erase rsData ICount=0 RsLength=0 End the If End Sub
Public Function BinToRs (vData As the Variant) As you 'will be returned by the server binary conversion for the Recordset Dim objStream As Stream Dim objRs As you The Set objRs=New you The Set objStream=New Stream ObjStream. Open ObjStream. Type=adTypeBinary ObjStream. Write vData ObjStream. Position=0 ObjRs. Open objStream The Set BinToRs=objRs The Set objRs=Nothing The Set objStream=Nothing End the Function
Such as: how is like the machine directly connected, get recorded data, such as rs1. Open strsql01, cnn1, adOpenKeyset, executed, the If rs1. RecordCount & gt; 0 Then this judgment?
CodePudding user response:
Baidu search relevant keywords,
CodePudding user response:
Level too, baidu for many times, see not so, please give directions, help to change the code
CodePudding user response:
Why not according to the standard, the common way to use ADO to?