《vb数据库应用编程》由会员分享,可在线阅读,更多相关《vb数据库应用编程(13页珍藏版)》请在金锄头文库上搜索。
1、文档供参考,可复制、编制,期待您的好评与关注! 数据库应用编程学院:信息工程学院班级学号:2402090213姓名:胡刚刚日期:2011年11月27日一.1.设计界面截图2.运行截图(1)(3)在查找系中输入“数学系”,按查找3.源代码Private Sub cmdSearch_Click()If Len(TxtSearchDept.Text) 0 ThenAdodcStudent.CommandType = adCmdTextAdodcStudent.RecordSource = select * from student where Sdept= & _Trim(TxtSearchDept
2、.Text) & AdodcStudent.RefreshElseMsgBox (请指定要查找的系)End IfEnd SubPrivate Sub cmdExit_Click()EndEnd SubPrivate Sub Form_Load()TxtSearchDept.Text = End Sub二.1.设计界面截图2运行截图(1)(2)演示按钮末一条功能(3)添加功能演示添加+更新+第一条3.源代码Private Sub cmdAdd_Click()AdodcStudent.Recordset.AddNewcmdAdd.Enabled = FalsecmdDel.Enabled = Fa
3、lsecmdUpdate.Enabled = TruecmdCancel.Enabled = TrueEnd SubPrivate Sub cmdCancel_Click()AdodcStudent.Recordset.CancelUpdatecmdAdd.Enabled = TruecmdDel.Enabled = TruecmdCancel.Enabled = FalseEnd SubPrivate Sub cmdDel_Click()Dim res As Integerres = MsgBox(确实要删除此行记录吗?, vbExclamation + vbYesNo + vbDefaul
4、tButton2)If res = vbYes ThenAdodcStudent.Recordset.DeleteAdodcStudent.Recordset.MoveNextIf AdodcStudent.Recordset.EOF = True ThenAdodcStudent.Recordset.MoveLastEnd IfEnd IfEnd SubPrivate Sub cmdExit_Click()EndEnd SubPrivate Sub cmdFirst_Click()AdodcStudent.Recordset.MoveFirstEnd SubPrivate Sub cmdLa
5、st_Click()AdodcStudent.Recordset.MoveLastEnd SubPrivate Sub cmdNext_Click()AdodcStudent.Recordset.MoveNextIf AdodcStudent.Recordset.EOF = True ThenAdodcStudent.Recordset.MoveLastEnd IfEnd SubPrivate Sub cmdPrevious_Click()AdodcStudent.Recordset.MovePreviousIf AdodcStudent.Recordset.BOF = True ThenAd
6、odcStudent.Recordset.MoveFirstEnd IfEnd SubPrivate Sub cmdUpdate_Click()AdodcStudent.Recordset.Fields(Sno) = Trim(TxtSno.Text)AdodcStudent.Recordset.Fields(Sname) = Trim(TxtSname.Text)AdodcStudent.Recordset.Fields(Ssex) = Trim(TxtSsex.Text)AdodcStudent.Recordset.Fields(Sage) = Trim(TxtSage.Text)Adod
7、cStudent.Recordset.Fields(Sdept) = Trim(TxtSdept.Text)AdodcStudent.Recordset.UpdatecmdAdd.Enabled = TruecmdDel.Enabled = TruecmdCancel.Enabled = FalseEnd SubPrivate Sub Form_Load()cmdCancel.Enabled = FalseEnd SubPrivate Sub Text4_Change()End Sub三.1.设计界面截图(1)form1(2)form22.运行截图(1)(2)按下查找后3.源代码(1)form
8、1Private Sub cmdExit_Click()EndEnd SubPrivate Sub cmdSearch_Click()Form2.ShowEnd Sub(2)form2Private Sub cmdReturn_Click()Unload MeEnd SubPrivate Sub Form_Load()Dim strSno As StringDim strSelect As StringstrSno = Trim(Form1.TxtSno.Text)strSelect = select sname,cname,scredit,grade from student s join
9、sc _& on s.sno=sc.sno join join course c on o=o where _& sc.sno= & strSno & AdodcGrid.CommandType = adCmdTextAdodcGrid.RecordSource = AdodcGridAdodcGrid.RefreshSet dtgCond.DataSource = AdodcGridCall InitGridEnd SubPrivate Sub InitGrid()With dtgCond.Columns(0).Caption = 学号.Columns(1).Caption = 课程名.Co
10、lumns(2).Caption = 学分.Columns(3).Caption = 成绩.Columns(0).Width = 1000.Columns(1).Width = 2000.Columns(2).Width = 800.Columns(3).Width = 800End WithEnd Sub四.1.设计截图2.运行截图(1)(2)添加功能演示添加+更新+末一条3源代码Dim adoCon As ADODB.ConnectionDim adoRst As ADODB.RecordsetPrivate Sub cmdAdd_Click()adoRst.AddNewcmdAdd.En
11、abled = FalsecmdDel.Enabled = FalsecmdUpdate.Enabled = TruecmdCancel.Enabled = TrueTxtSno.Text = TxtSname.Text = TxtSsex.Text = TxtSage.Text = TxtSdept.Text = End SubPrivate Sub cmdCancel_Click()adoRst.CancelUpdatecmdAdd.Enabled = TruecmdDel.Enabled = TruecmdCancel.Enabled = FalseCall DisplayEnd Sub
12、Private Sub cmdDel_Click()Dim res As Integerres = MsgBox(确实要删除此行记录吗?, vbExclamation + vbYesNo + vbDefaultButton2)If res = vbYes ThenadoRst.DeleteadoRst.NextRecordsetIf adoRst.EOF = True ThenadoRst .MoveLastEnd IfEnd IfCall DisplayEnd SubPrivate Sub cmdExit_Click()EndEnd SubPrivate Sub cmdUpdate_Clic
13、k()adoRst.Fields(Sno) = Trim(TxtSno.Text)adoRst.Fields(Sname) = Trim(TxtSname.Text)adoRst.Fields(Ssex) = Trim(TxtSsex.Text)adoRst.Fields(Sage) = Trim(TxtSage.Text)adoRst.Fields(Sdept) = Trim(TxtSdept.Text)adoRst.UpdatecmdAdd.Enabled = TruecmdDel.Enabled = TruecmdCancel.Enabled = FalseEnd SubPrivate
14、Sub Form_Load()Set adoCon = New ADODB.ConnectionadoCon.Open Provider=SQLOLEDB.1;Persist Security Info=False; _& User ID=sa;Initial Catalog=students; _& Data Sourse=(local)Set adoRst = New ADODB.RecordsetadoRst.ActiveConnection = adoConadoRst.CursorLocation = adUseClientadoRst.CursorType = adOpenDynamicadoRst.LockType = adLockOptimisticadoRst.Source = StudentadoRst.Open , , , , adCmdTableCall DisplaycmdCancel.Enabled = FalseEnd SubPrivate Sub Display()TxtSno.Text = convertNu