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?

CodePudding user response:

reference zhao4zhong1 reply: 3/f
why not according to the standard and common way to use ADO to?


It s also used the client direct database is too weak,
Literally at the connection string, in the memory of your database for others

CodePudding user response:

Chewinggum
reference 4 floor response:
Quote: reference zhao4zhong1 reply: 3/f

Why not according to the standard, the common way to use ADO to?


It s also used the client direct database is too weak,
Literally at the connection string, in the memory of your database to someone else

Isn't it?
http://bbs.csdn.net/topics/392143402

CodePudding user response:

Can help only refers to the fourth floor? First, thanks.

CodePudding user response:

refer to 6th floor jin1982253 response:
can help only refers to the fourth floor? Thanks, first


Put up a bunch of code, but did not say your business scenario,

1, the client access to records for the purpose of is what? See you the last question seems to be in order to record Numbers, if just in order to get the record number is not necessary to return record sets, the service side directly pass a record number, and if just in order to get the record number, use the select count faster,

2, visual do you want to send SQL statements to the server, then the server return data sets and the client after receiving treatment, strongly do not recommend you do so, once you have this communication by others see through, so he can send any SQL statement, proposed approach is the service side open a number of a single service interface function, such as your example take TOP 500 BillIndex encapsulated into an interface that is exposed to the client for example take TOP n BillIndex, client just call the interface, and inform the value of n, as to obtain the logic by server-side processing, access to what database access which form filter conditions all encapsulate business logic on the server, for the client is just a black box,

3, as to how to transfer the client data sets, Suggestions based on the TCP establishes a set of data transfer protocol, in accordance with your product characteristics on the baidu can draw lessons from, there are many around here

CodePudding user response:

Thank you upstairs said is very good, I send SQL statements to the client, server, client receives data sets, how to in various places, such as access number in the text box, or message from the form, good processing can, in the baidu search keywords?

CodePudding user response:

The seventh floor is not saying you send SQL statements from a client, you can send a request to the server, it use the SQL query defined in advance, and then, it sends the data to you, can be a format of a file,

Of course, you must send a SQL statement, so also can add a security filtering on the server, SQL statements about may endanger your safety refused to perform,

In brief, your work need to client and server two head to cooperate,

CodePudding user response:

Thanks for the seventh floor and the ninth floor of a friend, do you have any similar source provides the study? Not level, simple statement, it is a bit difficult to custom specifications

CodePudding user response:

nullnullnullnullnullnullnullnull
  • Related