Public bianhaozong
Private Sub Command1_Click()
sql = "select * from allusers where 1=1"
If Trim(Text1.Text) <> "" Then
sql = sql + " and username like '%" & Trim(Text1.Text) & "%'"
End If
If Trim(Text5.Text) <> "" Then
sql = sql + " and realname like '%" & Trim(Text5.Text) & "%'"
End If
Call GetData(sql)
End Sub
Private Sub Command2_Click()
Form10.Show
Unload Me
End Sub
Private Sub Command3_Click()
mycon.Open
Dim rs As New ADODB.Recordset
sql = "select * from [allusers] where id=" & bianhaozong & ""
rs.Open sql, mycon, 3, 3
If rs.EOF Then
mycon.Close
MsgBox "對不起你沒有選擇要修改的記錄,請在左邊串列框中選擇!如不知記錄可以通過上面查詢記錄", vbDefaultButton1, "對不起!"
Else
'修改資料
rs("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 ("修改成功")
End If
End Sub
Private Sub Command4_Click()
Dim sql
If Text2.Text = "" Then
MsgBox "請在左邊串列中選擇要洗掉的記錄"
Else
If MsgBox("真的洗掉該記錄?" & vbCrLf & " ", _
vbQuestion + vbOKCancel + vbDefaultButton2, "真的洗掉?") = vbOK Then
sql = "delete from [allusers] where id=" & bianhaozong & ""
mycon.Open
mycon.Execute (sql)
mycon.Close
'資料庫清空
Text2.Text = ""
Text3.Text = ""
Text4.Text = ""
Text6.Text = ""
Call GetData("select * from [allusers] order by id desc")
MsgBox ("洗掉成功")
Else
MsgBox "洗掉已取消!"
End If
End 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
Function GetData(sql)
MSFlexGrid1.Clear
mycon.Open
Dim rs As New ADODB.Recordset
rs.Open sql, mycon, 1, 1
If rs.EOF Then
Else
Dim i As Integer
With MSFlexGrid1
i = 1
.Rows = 1
Do While Not rs.EOF
i = i + 1
.Rows = i
.TextMatrix(i - 1, 1) = rs("id")
.TextArray(0) = ""
.TextMatrix(i - 1, 2) = CStr(rs("username"))
.TextArray(1) = "ID"
.TextArray(2) = "用戶名"
.ColWidth(0) = 300
.ColWidth(1) = 600
.ColWidth(2) = 1200
rs.MoveNext
Loop
End With
rs.Close
End If
mycon.Close
End Function
Function ShowData(str)
If str = "" Then
Exit Function
End If
Dim sql
sql = "select * from [allusers] where id =" & str & ""
Dim rs As New ADODB.Recordset
mycon.Open
rs.Open sql, mycon, 1, 1
If rs.EOF Then
MsgBox "對不起,資料庫已沒有任何用戶記錄,請添加!", , "系統提示"
Else
'顯示資料
Text2.Text = rs("username")
Text3.Text = rs("pwd")
Text4.Text = rs("addtime")
Text6.Text = rs("realname")
End If
mycon.Close
End Function
Private Sub MSFlexGrid1_Click()
Dim bianhao
bianhao = MSFlexGrid1.TextMatrix(MSFlexGrid1.RowSel, 1)
bianhaozong = bianhao
Call ShowData(bianhao)
End Sub
想將代碼中紅色顯示的id表列名,改成cx,怎么改啊
uj5u.com熱心網友回復:
那就把id改為cx啊。什么叫“怎么改”?
uj5u.com熱心網友回復:
請把報錯資訊截圖貼上來。uj5u.com熱心網友回復:
貼上錯誤的資訊,診斷一下.或者你把你的資料庫結構放一下.轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/60973.html
標籤:VB基礎類
上一篇:VB中在label中如何顯示橫線
下一篇:菜鳥提問vb做出入庫的問題
