……接上
Private Sub Form_Load()
Set mrc = RunSelect("select * from js", MsgText)
Set DataGrid1.DataSource = mrc
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
End Sub
Private Sub cmdreset_Click()
Set mrc = RunSelect("select * from js", MsgText)
Set DataGrid1.DataSource = mrc
If mrc.RecordCount >= 1 Then
Call DatagGrid1_Click
End If
End Sub
Private Sub cmdupdate_Click()
If MsgBox("真要修改工号为:" & Trim(Num.Text) & "的教师记录么?", vbYesNo + vbQuestion + vbDefaultButton1, "确认窗口") = vbYes Then
txtSQl = "upddate js set 姓名='" & Trim(Name.Text) & "',性别='" & Trim(Sex.Text) & _
"',系名='" & Trim(Classname.Text) & "',工龄'" & Trim(Age.Text) & "',职称'" & Trim(Glory.Text) & _
"',基本工资'" & Trim(Salary.Text) & "',备注'" & Trim(SQlcmd.Text) & _
"' where 工号='" & Trim(Num.Text) & "'"
RunSQl txtSQl, MsgText
Set mrc = RunSelect("select * from js ", MsgText)
Set DataGrid1.DataSource = mrc
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
End If
End Sub
Private Sub DataGrid1_Click()
If DataGrid1.Columns.Count >= 8 Then
Num.Text = DataGrid1.Columns(0).Text
Name.Text = DataGrid1.Columns(1).Text
Sex.Text = DataGrid1.Columns(2).Text
Classname.Text = DataGrid1.Columns(3).Text
Age.Text = DataGrid1.Columns(4).Text
Glory.Text = DataGrid1.Columns(5).Text
Salary.Text = DataGrid1.Columns(6).Text
SQlcmd.Text = DataGrid1.Columns(7).Text
txtSQl = "select * from kc where 教师工号='" & Trim(Num.Text) & "'" 'sasdasadadaassd
Set mrc2 = RunSelect(txtSQl, MsgText)
Set DataGrid2.DataSource = mrc2
End If
End Sub
Private Sub Form_Unload(Cancel As Integer)
Set cn = Nothing
End Sub
Private Sub cmdfirst_Click()
If mrc.RecordCount >= 1 Then
mrc.MoveFirst
Call DataGrid1_Click
End If
End Sub
Private Sub cmdlast_Click()
If mrc.RecordCount >= 1 Then
mrc.MoveLast
Call DataGrid1_Click
End If
End Sub
Private Sub cmdprior_Click()
If mrc.BOF = True Then
MsgBox "已到头!"
Else
mrc.MovePrevious
If mrc.BOF = True Then
mrc.MoveFirst
MsgBox "已是第一个"
End If
End If
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
End Sub
Private Sub cmdnext_Click()
If mrc.EOF = True Then
MsgBox "已到尾!"
Else
mrc.MoveNext
If mrc.EOF = True Then
mrc.MoveLast: MsgBox "已是最后一个"
End If
End If
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
End Sub
Private Sub cmdquery_Click()
txtSQl = "select * from js where"
If Len(Trim(Num.Text)) >= 1 Then
txtSQl = txtSQl & "工号='" & Num.Text & "'"
ElseIf Len(Trim(Name.Text)) >= 1 Then
txtSQl = txtSQl & "姓名='" & Name.Text & "'"
ElseIf Len(Trim(Sex.Text)) >= 1 Then
txtSQl = txtSQl & "性别='" & Sex.Text & "'"
ElseIf Len(Trim(Classname.Text)) >= 1 Then
txtSQl = txtSQl & "系名='" & Classname.Text & "'"
ElseIf Len(Trim(Age.Text)) >= 1 Then
txtSQl = txtSQl & "工龄=" & Age.Text
ElseIf Len(Trim(Glory.Text)) >= 1 Then
txtSQl = txtSQl & "职称='" & Glory.Text & "'"
ElseIf Len(Trim(Salary.Text)) >= 1 Then
txtSQl = txtSQl & "基本工资=" & Salary.Text
ElseIf Len(Trim(SQlcmd.Text)) >= 1 Then
txtSQl = txtSQl & "备注='" & SQlcmd.Text & "'"
Else
txtSQl = "select * from js"
End If
Set mrc = RunSelect(txtSQl, MsgText)
iferror (MsgText)
Set DataGrid1.DataSource = mrc
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
End Sub
Private Sub cmdquery2_Click()
If Len(Trim(SQlcmd.Text)) >= 10 And InStr(UCase$(Trim(SQlcmd.Text)), "SELECT") Then
txtSQl = Trim(SQlcmd.Text)
Else
txtSQl = "select * from js,kc where js.工号=kc.工号"
End If
Set mrc = RunSelect(txtSQl, MsgText)
iferror (MsgText)
Set DataGrid1.DataSource = mrc
End Sub
Private Sub cmdtotal_Click()
If Len(Trim(SQlcmd.Text)) >= 10 And InStr(UCase$(Trim(SQlcmd.Text)), "SELECT") Then
txtSQl = Trim(SQlcmd.Text)
Else
txtSQl = "select 性别,count(*) as 人数 from js group by 性别"
End If
Set mrc = RunSelect(txtSQl, MsgText)
Set DataGrid1.DataSource = mrc
End Sub
Private Sub iferror(MsgText As String)
If InStr(MsgText, "查询错误") Then
MsgBox "error in query!reset,try again!"
Set mrc = RunSelect("select * from js", MsgText)
Set DataGrid1.DataSource = mrc
If mrc.RecordCount >= 1 Then
Call DataGrid1_Click
End If
End If
End Sub
///////////程序还包括两个外接数据库名分别为js和kc,是否还有其他隐藏控件,就不道了。拜托各位大侠了 ,程序我上传到网盘上了,下.载.地.址.h t t p : / / u . 1 1 5 . c o m /file/ bh1fqq7o