Ò»¡¢Êý¾Ý¼Èë
ͨ¹ýVBÏòSQL ServerÊý¾Ý¿âÖмÈëÊý¾Ý£¬¿ÉÒÔʹÓÃÊý¾Ý°ó¶¨¿Ø¼þ¼ÈëÊý¾ÝÓëʹÓÃSQLÓï¾ä¼Èë
1.ÀûÓÃÊý¾Ý°ó¶¨¿Ø¼þ¼ÈëÊý¾Ý
ʹÓÃÊý¾Ý°ó¶¨¿Ø¼þ¼ÈëÊý¾Ý¿ÉÒÔÔËÐнÏÉٵĴúÂ룬ʵÏÖÏòÊý¾Ý¿âÖмÈëÊý¾Ý£¬Êý¾Ý°ó¶¨ºó£¬ÓÉÓÚÊý¾Ý°ó¶¨¿Ø¼þÒѾÓëÊý¾Ý±íÏàÁ¬½Ó£¬ËùÒÔÖ»Ðèͨ¹ýADO¿Ø¼þµÄAddNew·½·¨Ìí¼ÓÒ»ÌõеĿհ׼Ǽ£¬ÔÙͨ¹ýUpdate·½·¨±£´æµ±Ç°µÄ¼Ç¼£¬¼´¿ÉÍê³ÉÏòÊý¾Ý¿âÖмÈëÊý¾Ý¡£
Àý£ºÏòÊý¾Ý¿âÖÐÌí¼ÓÒ»Ìõ¼Ç¼
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | Private Sub cmdAdd_click() Adodc1.Recordset.AddNew End Sub Private Sub cmdSave_click() Dim I as Long for I =0 to 6 Adodc.Recordset.Fields(i).value=Text(i+1).text Next I Adodc1.Recoedset.Update MsgBox"Ìí¼ÓÐÅÏ¢³É¹¦£¡" End Sub |
¡¡¡¡
2.ʹÓÃInsertÓï¾ä¼ÈëÊý¾Ý
ʹÓÃSQLÓï¾ä¼ÈëÊý¾Ý£¬Í¨¹ýconnection¶ÔÏóµÄexecute·½·¨Ö´ÐÐSQLÓï¾ä£¬Óï·¨ÈçÏ£º
connection.execute ×Ö·û´®£¬¼Ç¼Êý£¬×Ö·û´®²ÎÊý
Àý£ºÏòstudentÊý¾Ý¿âÖÐÌí¼ÓÒ»ÌõѧÉúÐÅÏ¢
Dim cnn as ADODB.conection Dim rst as ADODB.recordset Private sub Form_Load() set cnn=New ADODB.connection set rst=new ADODB.recordset cnn.open"provider=SQLOLEDB;Persist security Info=True;User ID=sa;Initial Catalog=student;Data Source=." rst.open"select * from student_info",cnn set MSHFlexGrid.DataSource=rst End Sub Private sub cmdAdd_click() cnn.execute"insert into student_info(txtSID,txtName,txtSex;txtBornData,txtRuDate,txtClassNo)" & _ "values('" & txtSID & "','" & txtName & "','" & txtSex & "','" & txtBornDate & "','" & txtRuDate & "','" & txtClassNo & "')" End Sub |
¡¡¡¡
¶þ¡¢Êý¾Ýɾ³ý
ͨ¹ýVBɾ³ýÊý¾Ýʱ£¬²»½ö¿ÉÒÔʹÓÃSQLÓï¾äÖеÄDeleteÓï¾äÀ´ÊµÏÖ£¬Ò²¿ÉÒÔʹÓÃAD£Ï¿Ø¼þDelete·½·¨À´É¾³ýÊý¾Ý¡£
1.ʹÓÃADO¿Ø¼þDelete·½·¨É¾³ýÊý¾Ý
ʹÓÃADO¿Ø¼þDelete·½·¨É¾³ýÊý¾Ýʱ£¬±»É¾³ýµÄÊý¾ÝÐÅÏ¢±íÃæÉÏÊDZ»É¾³ýÁË£¬ÊµÖÊÉÏÊý¾Ý»¹´æÔÚÓëÄÚ´æÖУ¬Õâʱ»¹ÐèҪʹÓÃADO¿Ø¼þµÄUpdate·½·¨²ÅÄܹ»½«Êý¾Ý³¹µ×µØɾ³ý
Àý£ºÉ¾³ý±íÖеÄÖ¸¶¨¼Ç¼£º
Adodc1.Recordset.Delete
Adodc1.Recordset.Update
Àý£ºÍ¨¹ýADO¿Ø¼þDelete·½·¨É¾³ý±íÖÐÖ¸¶¨µÄÊý¾Ý£º
Private Sub Form_Load() Adodc1.ConnectionString="Provider=SQLOLEDB;Persist Security Info=True;User ID=sa;Initail Catalog=student;Data Source=." Adodc1.Commandtype=adCmdText Adodc.Recordsource="select * from student_info" Set DataGrid1.DataSource=Adodc1 End Sub Private Sub Command1_Click() Adodc1.Recordset.Delete If Msgbox("È·ÈÏɾ³ýÖ¸¶¨Êý¾ÝÂð£¿",vbYesNo,"Ìáʾ")=vbYes then Adodc1.Recordset.Refresh End If End Sub |
¡¡¡¡
2.Ö´ÐÐDeleteÓï¾ä½øÐÐÊý¾Ýɾ³ý
ʹÓÃDeleteÓï¾äɾ³ýÊý¾Ý£¬²»½ö¿ÉÒÔɾ³ýÖ¸¶¨µÄÒ»Ìõ»ò¶àÌõÓï¾ä£¬Ò²¿ÉÒÔ½«Êý¾Ý±íÖеÄÊý¾ÝÈ«²¿É¾³ý
Àý£ºÔÚVBÖÐÖ´ÐÐDeleteÓï¾äɾ³ý±ístudentÖеÄÈ«²¿Êý¾Ý
Cnn.Execute"delete from student"
¿ÉÒÔÔÚDeleteÓï¾äºóʹÓÃwhereÀ´ÏÞ¶¨Ìõ¼þ£¬½«Ìõ¼þ·ûºÏµÄÊý¾Ýɾ³ý
Àý£ºÉ¾³ý±ístudentÖÐÄêÁä´óÓÚ25ËêµÄÊý¾Ý
Cnn.Execute"delete from student where ÄêÁä>'25'" |
¡¡¡¡
3.ɾ³ýÁÐÖеÄÊý¾Ý
ÎÞÂÛÊÇͨ¹ýADO¿Ø¼þDelete·½·¨»¹ÊÇdeleteÓï¾äɾ³ýÊý¾Ý£¬¶¼Êǽ«Ò»Ðлò¶àÐÐÊý¾ÝÈ«²¿É¾³ý£¬Èç¹û±íÖÐһЩÐеÄÊý¾ÝÐèÒª±£ÁôijЩÁÐÖеÄÐÅÏ¢£¬ÄÇôʹÓÃADO¿Ø¼þDelete·½·¨»òDeleteÓï¾ä¶¼ÊDZȽÏÂé·³µÄ¡£
¶ÔÓÚɾ³ý±íÖеÄÊý¾Ý£¬¿ÉÒÔ²ÉÈ¡Êý¾ÝµÄ·½Ê½ÊµÏÖ£¬¼´½«É¾³ýÁÐÖеÄÊý¾ÝÖ±½Ó¸üÐÂΪNull
Àý£ºÍ¨¹ýADO¿Ø¼þUpdate·½·¨É¾³ý±íÖÐÁеÄÊý¾Ý
Private Sub Command1_Click() Adodc1.Recordset.Update 1,Nul End Sub |
¡¡¡¡
Èý¡¢Êý¾ÝÐÞ¸Ä
ÔÚVBÖÐÐÞ¸ÄÊý¾Ý£¬²»½ö½ö¿ÉÒÔ²ÉÓÃÖ´ÐÐSQLÓï¾äʵÏÖ£¬Ò²¿ÉÒÔͨ¹ýÊý¾Ý°ó¶¨¿Ø¼þ½øÐÐÊý¾ÝµÄÐ޸ġ£Êý¾Ý°ó¶¨¿Ø¼þ½øÐÐÊý¾ÝµÄÐ޸IJÉÓõĴúÂë½ÏÉÙ£¬ÌرðÊÇһЩ±í¸ñÀàÊý¾Ý°ó¶¨¿Ø¼þ£¬²»ÐèÒª´úÂë¼´¿É¶ÔÊý¾Ý½øÐÐÐ޸ģ¬ÈçDataGrid¿Ø¼þ¡£
1.ʹÓÃUpdateÓï¾äÐÞ¸ÄÊý¾Ý
UpdateÓï¾äͨ¹ýADO¶ÔÏóµÄExecute·½·¨Ö´ÐУ¬´ïµ½¶ÔÊý¾Ý±íÖеÄÊý¾Ý½øÐÐÐÞ¸Ä
Cnn.Execute"Update Êý¾Ý±íÃû³Æ set ×Ö¶Î1=±í´ïʽ1£¬×Ö¶Î2=±í´ïʽ2¡¡where×Ó¾ä"
ÔÚUpdateÓï¾äÖпÉÒÔʹÓÃwhere×Ӿ䣬»¹ÓзûºÏÌõ¼þµÄÊý¾Ý¿ÉÖ´ÐÐÐ޸IJÙ×÷£¬Èç¹ûʹÓÃwhereÖ¸¶¨Ìõ¼þ£¬ÔòUpdateÓï¾ä»áÐ޸ıíÖеÄÈ«²¿Êý¾Ý
ͨ³£¶¼ÊÇÔÚÅúÁ¿¸ü¸Äʱ²ÉÓøÃÓï¾ä£¬ÕâÖÖ·½·¨Òª±ÈADOµÄUpdate·½·¨ÖðÌõµØÐÞ¸ÄÊý¾Ý·½±ã£¬µ«VBÖÐһЩ±í¸ñ¿Ø¼þ¿ÉÒÔ²»ÐèÒª´úÂë¶øÖ±¹ÛʵÏÖÊý¾ÝµÄÅúÁ¿ÐÞ¸Ä
2.±í¸ñÊý¾Ý°ó¶¨¿Ø¼þÐÞ¸ÄÊý¾Ý
ÔÚVBÖвÉÓñí¸ñÊý¾Ý°ó¶¨Ð޸ĿؼþÐÞ¸ÄÊý¾Ý£¬»ù±¾Éϲ»ÐèÒª´úÂ룬ֻÐèÒªÉèÖñí¸ñÊý¾Ý°ó¶¨¿Ø¼þµÄһЩÊôÐÔ¼´¿ÉʵÏÖ£¬ÀýÈçDataGrid¿Ø¼þ£¬½«Æä°ó¶¨µ½ÏàÓ¦µÄÊý¾ÝÔ´ÉÏ£¬ÔÙÉèÖÃÆäAllowUpdateÊôÐÔΪTrue£¬¼´¿ÉʵÏÖ±í¸ñÖÐÐ޸ĵÄÊý¾Ý¼°Ê±¸üе½Êý¾Ý¿âÖÐ
¸ÃÊôÐÔ¿É·µ»Ø»òÉèÖÃÒ»¸öÖµ£¬Ö¸Ê¾Óû§ÄÜ·ñÐÞ¸ÄDataGrid¿Ø¼þÖеÄÊý¾Ý£¬Óï·¨£º
DataGrid.AllowUpdate=²¼¶û±í´ïʽ
Àý£ºÊ¹ÓÃDataGrid¿Ø¼þÐÞ¸ÄÊý¾Ý
Private Sub Form_Load£¨£© 'ÉèÖÃÁ¬½Ó×Ö·û´® Adodc1.ConnectionString="Provider=SQLOLEDB;Persist Security Info=True;User ID=sa;Initial Catalog=student;Data Source=." 'É趨Êý¾ÝÔ´ Adodc1.CommandType=adcmdText Adodc1.RecordSource="select * from student_Info order by student_ID" 'ΪDataGrid¿Ø¼þ°ó¶¨Êý¾ÝÔ´ Set DataGrid1.DataSouce=Adodc1 'ÔÊÐíDataGrid1¿Ø¼þ¸üбíÖеÄÊý¾Ý DataGrid1.AllowUpdate=True End Sub |
¡¡¡¡
3.ʹÓÃÎı¾Êý¾Ý°ó¶¨¿Ø¼þÐÞ¸ÄÊý¾Ý
ÓëDataGrid¿Ø¼þ²»Í¬£¬Îı¾Àà¿Ø¼þ°ó¶¨Êý¾ÝºóÔÚÐÞ¸ÄÊý¾Ýʱ£¬ÓÉÓÚËùÐ޸ĵÄÊý¾ÝÖ»ÊÇдÈëÔÚ»º´æµ±ÖУ¬ËùÒÔÐèҪͨ¹ýADOµÄUpdate·½·¨Ìá½»Ð޸ģ¬ÁíÍ⣬ADO»¹ÌṩCancelUpdate·½·¨£¬Óô˷½·¨À´³·ÏúÔÚʹÓÃUpdate·½·¨Ç°¶ÔÊý¾ÝËù×÷µÄÐ޸ģ¬ÔÚ³ÌÐòÖÐʹÓÃCancelUpdate·½·¨µÄ´úÂëÈçÏ£ºAdodc1.Recordset.CancelUpdate
Àý£ºÊ¹ÓÃÎı¾¿Ø¼þ°ó¶¨Êý¾Ý²¢½øÐÐÐÞ¸ÄÊý¾Ý
'ÉèÖÃÁ¬½Ó×Ö·û´®ÓëÊý¾ÝÔ´£¬²¢°ó¶¨Êý¾ÝÔ´ Private Sub Form_Load() Adodc1.ConnectiongString="Provider=SQLOLEDB;Persist Security Info=True;User ID=sa;Initial Catalog=student;Data Source=." Adodc1.RecordSource="select * from Course_Info" Set Text1.DataSource=Adodc1 Text1.DataField="¿Î³ÌÃû³Æ" End Sub 'Ìá½»±£´æÊý¾Ý Private Sub Commad1_Click() Adodc1.Recordset.Update MsgBox"±£´æ³É¹¦£¡",vbOKOnly,"Ìáʾ" End Sub '³·ÏúÊý¾ÝÐÞ¸Ä Private Sub Command2_Click() Adodc1.Recordset.CancelUpdate End Sub |
¡¡¡¡
ËÄ¡¢Êý¾Ý²éѯ
VBÖвéѯÊý¾Ý¿âÖеÄÊý¾Ý²»½ö¿ÉÒÔͨ¹ýÖ´ÐÐSQLÓï¾äʵÏÖ£¬Ò²¿ÉÒÔͨ¹ý¿Ø¼þ»ò¶Ô£¨ÈçADO£©ÏÞ¶¨¼ìË÷Êý¾ÝµÄÌõ¼þÀ´ÊµÏÖ¡£
1.¼òµ¥²éѯ
¼òµ¥²éѯ¿ÉÒÔͨ¹ýSelectÓï¾äÏÞ¶¨Êý¾ÝÔ´À´ÊµÏÖ¡£ÔÚSelectÓï¾äÖÐʹÓùؼü×Ö¡¢×Ó¾äµÈʵÏÖ¡£
ÏÂÃæ¶Ô¼¸ÖÖ³£Óõļòµ¥²éѯ½øÐнéÉÜ£º
1£©Ê¹ÓÃAS¸Ä±ä²éѯÊý¾ÝµÄÁÐÃû
¶àÊýÇé¿öÏ£¬ÔÚSQL ServerÖд´½¨±íµÄ×ֶζ¼ÊÇÒÔÓ¢ÎÄÃüÃûµÄ£¬ÕâЩ×Ö¶ÎÃûÔÚÏÔʾʱ¸øÒ»°ãÓû§´øÀ´²»±ã£¬ÄÇô¿ÉÒÔÔÚ²éѯÖвÉÓÃASÀ´¸Ä±ä×Ö¶ÎÔÚÏÔʾʱµÄÃû³Æ¡£
Àý£ºÊ¹ÓÃAS¸Ä±ä²éѯÊý¾ÝµÄÁÐÃû
Private Sub cmdModify_Click() Adodc.RecordSource="select ID as ±àºÅ,Mailbox as µç×ÓÓÊÏä from Mail_Info" Adodc.Refresh End Sub |
¡¡¡¡
2£©¼ÆËã²éѯµÄ½á¹û
VB±àдµÄ³ÌÐòÖУ¬ÍùÍùÐèÒª½«Êý¾Ý¿âÖеÄÊý¾Ý½øÐмÆË㣬ÒÔ±ã»ñµÃËùÐèµÄÊýÖµ¡£
ͨ¹ýÔÚ²éѯÓï¾äÖÐʹÓÃËãÊõÔËËã·û£¬ÔÚÅäºÏASΪ¼ÆËã³öµÄ×Ö¶ÎÉèÖÃÃû³Æ£¬¼´¿ÉÔÚ²éѯ½á¹ûÖÐÏÔʾ¼ÆËãµÃµ½µÄÊý¾Ý¡£
Àý£º¼ÆËã²éѯµÄ½á¹û
Private Sub cmdAcount_Click() Adodc.RecordSource="select ¿¨ºÅ,ÿСʱÉÏ»ú·ÑÓã¬ÉÏ»úʱ¼ä£¨Ã¿Ð¡Ê±ÉÏ»ú·ÑÓÃ*ÉÏ»úʱ¼ä£©as Êշѽð¶î from ѧÉúÉÏ»úÊշѽð¶î±í" Adodc.Refresh End Sub |
¡¡¡¡
3£©±È½ÏÌõ¼þ²éѯ
ÔÚ²éѯÓï¾äÖпÉÒÔ°üº¬±È½ÏÔËË㣬³£ÓõıȽÏÔËËã·ûÓÐ=¡¢<¡¢>¡¢<>¡¢!>¡¢!<¡¢>=¡¢<=¡¢!=¡£Ê¹ÓÃÕâЩÔËËã·ûÁ¬½Ó±í´ïʽÐγÉÒ»¸ö±È½ÏÌõ¼þ£¬ÏµÍ³½«¸ù¾ø¸Ã²éѯÌõ¼þ·µ»ØµÄ²¼¶ûÖµÀ´ÅжÏÊý¾ÝÊÇ·ñÂú×ã¸Ã²éѯÌõ¼þ£¬Ö»ÓÐÂú×ãÌõ¼þµÄÊý¾Ý²Å»á³öÏÖÔÚ²éѯµÄ½á¹û¼¯ÖС£
ÕâЩ±È½ÏÌõ¼þÔÚ²éѯÓï¾äÖÐÐèÒªÓëwhere×Ó¾äÁ¬Ó㬵«ÊÇVBÌṩFilterÊôÐÔΪRecordsetÖеÄÊý¾ÝÖ¸¶¨É¸Ñ¡Ìõ¼þ¡£¸ÃÊôÐÔ¸ù¾ÝÌõ¼þ¿ÉÑ¡ÔñÐÔµØÆÁ±ÎRecordset¶ÔÏóÖеļǼ£¬¸ÃÊôÐÔÓï·¨ÈçÏ£ºRecordset.Filter=×Ö·û´®
Àý£ºÍ¨¹ýFilterÊôÐÔʵÏֱȽÏÌõ¼þ²éѯ
'ÉèÖÃÁ¬½Ó¡¢Êý¾ÝÔ´Óë³õʼ»¯³ÌÐò Private Sub Form_Load() Adodc.connectionString="provider=SQLOLEDB;Data Source=.;Initail CataLog=student;UID=sa;PWD=123456" Adodc.Recordset="select stuID as ѧºÅ,stuname as ÐÕÃû,stuage as ÄêÁä from student_info" set DataGrid.DataSource=Adodc Combo1.AddItem"ѧºÅ" Combo1.AddItem"ÐÕÃû" Combo1.AddItem"ÄêÁä" Combo2.AddItem">" Combo2.AddItem"<" Combo2.AddItem">=" Combo2.AddItem"<=" Combo2.AddItem"=" End Sub '²éѯÐÅÏ¢ÒÔ¼°´íÎó´¦ Private Sub cmdQuery_Click() On Error Resume Next If Combo1.text<>"" and Combo2.text<>"" then Adodc.Recordset.Filter=Adodc.Recordset.Fields(Combo1.ListIndex).Name & Combo2.Text & "" & Trim(txtQuery.text) & "" End If If Err then Msgbox"ÇëÊäÈëÕýÈ·ÐÅÏ¢£¡",vbOKOnly,"¾¯¸æ" End Sub |
¡¡¡¡
2.Ä£ºý²éѯ
Ä£ºý²éѯÊÇͨ¹ýÔÚVBÖвéѯÓëËù¸ø²éѯÄÚÈÝÏàËƵÄÐÅÏ¢¡£
ʵÏÖÄ£ºý²éѯ¿ÉÒÔͨ¹ýÖ´ÐÐSQLÓï¾äÖеÄLikeÓï¾äʵÏÖ¡£LikeÓï¾äÓÃÀ´È·¶¨¸ø¶¨µÄÊý¾ÝÐÅÏ¢ÊÇ·ñÓëÖ¸¶¨µÄģʽƥÅä¡££¨Ä£Ê½¿ÉÒÔ°üº¬³£¹æ×Ö·ûºÍͨÅä·û×Ö·û¡££©LikeÒ²¿ÉÒÔÔÚADOµÄFilterÊôÐÔÖÐʹÓá£
ÏÂÃæ½éÉÜÔÚFilterÊôÐÔÖÐʹÓÃLikeÓëͨÅä·ûµÄ¼¸ÖÖ·½·¨£º
3.ÈÕÆÚºÍʱ¼ä²éѯ
¶ÔÈÕÆÚºÍʱ¼äµÄÊý¾Ý²éѯ£¬¿ÉÒÔͨ¹ýVBÖеÄADOµÄFilterÊôÐÔÏÞ¶¨É¸Ñ¡Ìõ¼þ£¬»òÖ´ÐвéѯSQLÓï¾äʵÏÖ¡£
1£©²éѯָ¶¨ÈÕÆÚʱ¼äµÄÊý¾Ý
ÔÚSQLÓï¾äÖУ¬¿ÉÒÔʹÓÃÔËËã·û£¨>¡¢=¡¢<¡¢LikeµÈ£©²éѯÈÕÆÚ/ʱ¼äÀàÐ͵ÄÊý¾Ý¡£ÈÕÆÚʱ¼ä×Ö·û´®µÄÊéдҪ·ûºÏÒ»¶¨µÄ¸ñʽ£¬ÀýÈç¡°2012-08-13 0:00:01¡±¡£
Àý£º²éѯָ¶¨ÈÕÆÚʱ¼äµÄÊý¾Ý
Private Sub cmdQuery_Click() On Error Resume Next Adodc.Recordset.Filter="³öÉúÈÕÆÚ="' & Trim(txtYear.Text) & "-" & Trim(txtMonth.Text) & "-" & Trim(txtDay.Text) & "0:00:00"' If Err then Msgbox"ÇëÊäÈëÕýÈ·ÐÅÏ¢£¡",vbOKOnly,"´íÎó" End sub Private Sub Form_Load() Adodc.ConnectonString="Provider=SQLOLEDB;Data Source=.;Initail Catalog=student;UID=sa;PWD=123456" Adodc.RecordSource="select stuID as ѧºÅ,stuName as ÐÕÃû,stuAge as ÄêÁä,stuBornDate as ³öÉúÈÕÆÚ from Student_Info" set DataGrid.DataSource=Adodc End Sub |
¡¡¡¡
2£©·Ö±ð°´Äê¡¢Ô¡¢ÈյȲéѯÊý¾Ý
ÔÚÉè¼ÆÊý¾Ý¿âϵͳӦÓóÌÐòʱ£¬ÍùÍùÐèÒª²éѯijһÄꡢij¸öÔ»òijһÌìµÄÊý¾Ý¡£Èç¹û²ÉÓÃÖ¸¶¨ÈÕÆÚʱ¼äµÄ·½Ê½À´²éѯ£¬ËäÈ»¿ÉÒÔʵÏÖ£¬µ«Êǹý³ÌÊǺÜÂé·³µÄ¡£Õâʱ¿ÉÒÔ²ÉÓÃYear¡¢Month¡¢DayµÈº¯Êý£¬¶ÔÊý¾Ý¿âÖÐÈÕÆÚʱ¼äÊý¾ÝÌáÈ¡Äê¡¢Ô¡¢ÈÕµÈÏà¹ØÐÅÏ¢£»È»ºó½áºÏÖ¸¶¨ÈÕÆÚʱ¼äµÄ²éѯ·½Ê½£¬¼´¿É·½±ãµØ²éѯµ½Ä³Ò»Äꡢij¸öÔ»òÕßijһÌìµÄÊý¾Ý¡£
Àý£º°´Äê¡¢Ô¡¢ÈյȲéѯÊý¾Ý
Private Sub cmdQuery_Click() Dim stc as string On Error Resume Next Select Case combo1.ListIndex Case 0 stc="year" Case 1 stc="month" Case 2 stc="day" End Select Adodc.RecordSource="select stuID as ѧºÅ,stuName as ÐÕÃû,stuAge as ÄêÁä,stuBornDate as ³öÉúÈÕÆÚ from Student_Info where " & stc & "(stuBornDate)='" & txtQuery.Text & "'" Adodc.Refresh If Err then Msgbox"ÇëÊäÈëÕýÈ·ÐÅÏ¢£¡",vbOKOnly,"´íÎó"\ End Sub Private Sub Form_Load() Adodc.ConnectonString="Provider=SQLOLEDB;Data Source=.;Initail Catalog=student;UID=sa;PWD=123456" Adodc.RecordSource="select stuID as ѧºÅ,stuName as ÐÕÃû,stuAge as ÄêÁä,stuBornDate as ³öÉúÈÕÆÚ from Student_Info" set DataGrid.DataSource=Adodc combo1.AddItem"°´Äê" combo1.AddItem"°´ÔÂ" combo1.AddItem"°´ÈÕ" End Sub |