Home > Software engineering >  VB call SQL database according to data errors
VB call SQL database according to data errors

Time:09-21

Public bianhaozong

Private Sub Command1_Click ()
SQL="select * from allusers where 1=1"
If the Trim (Text1. Text) & lt;> "" Then
SQL=+ SQL "and the username like '%" & amp; Trim (Text1. Text) & amp; "% '
"
End the If
If the Trim (Text5. Text) & lt;> "" Then
SQL=+ SQL "and realname like '%" & amp; Trim (Text5. Text) & amp; "% '
"
End the If
Call GetData (SQL)
End Sub

Private Sub Command2_Click ()
Form10. Show
Unload Me
End Sub

Private Sub Command3_Click ()
Mycon. Open
Dim the rs As New ADODB. You
SQL="select * from [allusers] where id=" & amp; Bianhaozong & amp; "
"Rs. The Open SQL, mycon, 3, 3
If the rs. EOF Then
Mycon. Close
MsgBox "I'm sorry you have no choice to change the record, please choose in the list box on the left! Records such as do not know can be through the query above records, "vbDefaultButton1," sorry!"
The Else
'
modify dataRs (" username ")=Trim (Text2. Text)
Rs (" PWD ")=Trim (Text3. Text)
Rs (" realname ")=Trim (Text6. Text)
Rs. Update
Rs. Close
Mycon. Close
Call GetData (" select * from [allusers] ")
MsgBox (" success ")
End the If
End Sub

Private Sub Command4_Click ()
Dim SQL
If Text2. Text="" Then
MsgBox "on the left in the list, please choose to delete the record"
The Else
If MsgBox (" really delete this record?" & VbCrLf & amp; ", "_
VbQuestion + vbOKCancel + vbDefaultButton2, "really delete?" )=vbOK Then
SQL="delete from [allusers] where id=" & amp; Bianhaozong & amp; "
"Mycon. Open
Mycon. Execute (SQL)

Mycon. Close
'database to empty

Text2. Text=""
Text3. Text=""
Text4. Text=""
Text6. Text=""

Call GetData (" select * from [allusers] order by id desc ")
MsgBox (" delete "success)
The Else
MsgBox "remove cancelled!"
End the If
End the If
End Sub

Private Sub Command5_Click ()
Unload Me
End Sub

Private Sub Form_Load ()
Call GetData (" select * from allusers order by id desc ")
End Sub
The Function GetData (SQL)
MSFlexGrid1. Clear
Mycon. Open
Dim the rs As New ADODB. You
Rs. The Open SQL, mycon, 1, 1
If the rs. EOF Then
The Else
Dim As Integer I
With MSFlexGrid1
I=1
. The Rows=1
EOF
the Do While Not rs.I=I + 1
The Rows=I
TextMatrix (I - 1, 1)=rs (" id
")TextArray (0)=""
TextMatrix (I - 1, 2)=CStr (rs (" username "))


TextArray (1)="ID"

TextArray (2)="user name"

ColWidth (0)=300
ColWidth (1)=600
ColWidth (2)=1200

Rs. MoveNext
Loop
End With
Rs. Close
End the If
Mycon. Close
End the Function
The Function ShowData (STR)
If the STR="" Then
The Exit Function
End the If
Dim SQL
SQL="select * from [allusers] where id=" & amp; STR & amp; "
"Dim the rs As New ADODB. You
Mycon. Open
Rs. The Open SQL, mycon, 1, 1
If the rs. EOF Then
MsgBox "sorry, there is no any user database has been recorded, please add!" , and "prompted"
The Else
'display data
Text2. Text=rs (" username ")
Text3. Text=rs (" PWD ")
Text4. Text=rs (" addtime ")
Text6. Text=rs (" realname ")


End the If

Mycon. Close
End the Function

Private Sub MSFlexGrid1_Click ()
Dim bianhao
Bianhao=MSFlexGrid1. TextMatrix (MSFlexGrid1 RowSel, 1)
Bianhaozong=bianhao
Call ShowData (bianhao)
End Sub

Want to display the id of the table column name in the code red, cx, to how to change

CodePudding user response:

Then put the id ,
What is "how to"?

CodePudding user response:

, the error message corresponding to the front, please,

CodePudding user response:

Put a wrong information, diagnose. Or you put your database structure.
  • Related