Home > Software engineering >  Rookie help, in the VB interface can add or remove data but there is no data in SQL
Rookie help, in the VB interface can add or remove data but there is no data in SQL

Time:09-16

In VB visual interface can add or remove data but there is no data in SQL, according to the table are empty inside, as the chart


Below is the code:
Public fMainForm As frmMain
Public gintSmode As Integer 'for service
Public gintPmode As Integer 'for plane
Public gintAmode As Integer 'for airline
For Public gintTmode As Integer 'customertype
Public gintCmode As Integer 'for the customer
Public gintKmode As Integer 'for ticket
Sub Main ()
Dim fLogin As New frmLogin
FLogin. Show vbModal
If Not fLogin. OK Then
'the Login Failed so exit the app
End
End the If
Unload fLogin


The Set fMainForm=New frmMain
FMainForm. Show
End Sub

The Public Function ConnectString () _
As the String
'returns a DB ConnectString
'the ConnectString="FileDSN=ticket. The DSN; UID=sa; The PWD="
ConnectString="PROVIDER=Microsoft. Jet. The OLEDB. 4.0. Data Source=Data/ticket. MDB;"
End the Function
The Public Function the ExecuteSQL (ByVal SQL _
As a String, MsgString As String) _
As the ADODB library you
'executes the SQL and returns you
Dim CNN As ADODB. Connection
Dim RST As ADODB. You
Dim sTokens () As String

On Error GoTo ExecuteSQL_Error

STokens=Split (SQL)
Set the CNN=New ADODB. Connection
CNN. Open ConnectString
If InStr (" INSERT, DELETE, UPDATE, "_
Then UCase $(sTokens (0)))
CNN. The Execute SQL
MsgString=sTokens (0) & amp; _
The query "successful"
The Else
The Set RST=New ADODB. You
RST. Open Trim $(SQL), CNN, _
AdOpenKeyset, _
AdLockOptimistic
'RST. MoveLast get RecordCount
Set the ExecuteSQL=RST
MsgString="query" & amp; RST. RecordCount & amp; _
"Records"
End the If
ExecuteSQL_Exit:
The Set of RST=Nothing
The Set of CNN=Nothing
The Exit Function


ExecuteSQL_Error:
MsgString="query error:" & amp; _
Err. The Description
Resume ExecuteSQL_Exit
End the Function
Public Sub EnterToTab (Keyasc As Integer)
If Keyasc=13 Then
SendKeys "{TAB}
"End the If
End Sub
The Public Function GetRkno () As String
GetRkno=Format (Now, "yymmddhhmmss")
Randomize
GetRkno=GetRkno & amp; Int (Rnd (99-10 + 1) * + 10)
End the Function

CodePudding user response:

Your connection is ACCESS database (data/ticket. MDB) ah, how to run the SQL inside to see the results?

CodePudding user response:

VB database records is need VB data display controls, VB can't shown in the SQL database records,
VB data showed that the control is more, each has his strong point, more commonly used include MSHFlexGrid control, TreeView control, ListView control that MSFlexGrid control, etc.,
Of course in the use of different control shows the database record is the need to display code, control code is also different,
As to what the database with the controls basically the relationship is not very big, is to connect to the database SQL statements different,
ConnectString="PROVIDER=Microsoft. Jet. The OLEDB. 4.0. Data Source=Data/ticket. MDB;"
CNN. Open ConnectString
Your statement is basically the path of the database, but
RST. Open Trim $(SQL), CNN, adOpenKeyset, adLockOptimistic in found no SQL record set connection string , so we can not open the recordset, also is unable to read data in the table records, not to mention according to records,
  • Related