當前位置:ag真人国际官网-ag旗舰厅官方网站 » 操作系統 » vb資料庫代碼

vb資料庫代碼-ag真人国际官网

發布時間: 2024-11-11 01:41:06

① vb實現access資料庫記錄的查詢,新增,刪除,修改的代碼是什麼

「修改」按鈕的程序 x0dx0aprivate sub cmdedit_click() x0dx0asql = "select * from 停時禪橡旅統如液計 where date = cdate('" & text8.text & "') and ycqk = '" & combo1.text & "'and id = '" & datagrid1.columns(2).celltext(datagrid1.bookmark) & "'" x0dx0ars.open sql, dm, adopendynamic, adlockoptimistic x0dx0ars.fields("id") = text7.text x0dx0ars.fields("ycqk") = combo1.text x0dx0ars.fields("date1") = text1.text x0dx0ars.fields("time1") = text2.text x0dx0ars.fields("date2") = text3.text x0dx0ars.fields("time2") = text4.text x0dx0ars.update x0dx0ars.close x0dx0aend sub x0dx0ax0dx0a'「刪除」按鈕的程序 x0dx0aprivate sub cmddelete_click() x0dx0astrfcode = datagrid1.columns(0).celltext(datagrid1.bookmark) x0dx0astrscode = datagrid1.columns(2).celltext(datagrid1.bookmark) x0dx0astrccode = datagrid1.columns(1).celltext(datagrid1.bookmark) x0dx0asql = "select * from 停時統計 where date='" & strfcode & "' and id='" & strscode & "' and ycqk='" & strccode & "'" x0dx0ars.open sql, dm, adopendynamic, adlockoptimistic x0dx0ars.delete x0dx0ars.update x0dx0ars.close x0dx0aend sub x0dx0ax0dx0a'「增加」按鈕的程序 x0dx0aprivate sub command1_click() x0dx0asql = "select * from 停時賀凳統計 order by id" x0dx0ars.open sql, dm, adopendynamic, adlockoptimistic x0dx0ars.addnew x0dx0ars.fields("date") = date x0dx0ars.fields("id") = text7.text - 1 x0dx0ars.fields("ycqk") = combo1.text x0dx0ars.fields("date1") = text1.text x0dx0ars.fields("time1") = text2.text x0dx0ars.fields("date2") = text3.text x0dx0ars.fields("time2") = text4.text x0dx0ars.update x0dx0ars.close x0dx0ax0dx0awith adodc1 x0dx0aadodc1.connectionstring = "provider=microsoft.jet.oledb.4.0;data source=" & app.path & "\db1.mdb;persist security info=false" x0dx0aadodc1.recordsource = "select * from 停時統計 where date = cdate('" & text8.text & "') and ycqk = '" & combo1.text & "' order by id" x0dx0aadodc1.refresh x0dx0adatagrid1.refresh x0dx0aend with x0dx0aend sub

② vb資料庫編程,資料庫某些欄位不能重復,如果錄入數據有重復,保存時,程序自動提醒,怎麼編寫自動提醒代碼。

用sql語句,查詢或者find方法查詢,如果已經存在該記錄,就提醒:

如果一下子要保存n行,那有兩種選擇:
1:檢查一行,保存一行。凡是沒有重復的都保存,有重復的不保存。
2:先一一檢查,檢查到有重復就提示,並結束。

不知道你用的是控制項還是對象連接的資料庫?假設你用adodc控制項,且已經連接。
下面:假設欄位a,b為字元類型,以一行數據為例,a欄位值為「aa」,b欄位值為「bb」,
adodc1.recordsource ="select * from s where a ='aa' and b = 'bb'"
adodc1.refresh
if not (adodc1.recordset.eof and adodc1.recordset.bof) then
msgbox "已經存在相同記錄!"
exit sub
else
'下面編寫添加記錄的代碼
end if

上面是當數據a,b一樣提示,如果a一樣或者b一樣就提示,那麼:
adodc1.recordsource ="select * from s where a ='aa' or b = 'bb'"

熱點內容
接龍源碼 發布:2024-11-19 10:14:48 瀏覽:33
驅動軟體哪個安卓版好 發布:2024-11-19 10:08:28 瀏覽:703
伺服器一鍵搭建java環境 發布:2024-11-19 10:08:27 瀏覽:729
布丁少兒編程 發布:2024-11-19 09:57:11 瀏覽:98
vb資料庫數組 發布:2024-11-19 09:23:40 瀏覽:828
安卓游戲數據保存在哪裡找 發布:2024-11-19 09:22:02 瀏覽:310
解壓出來的文件亂碼 發布:2024-11-19 09:15:40 瀏覽:940
北航ftp是多少 發布:2024-11-19 09:15:32 瀏覽:822
瀏覽保存密碼如何取消 發布:2024-11-19 09:10:17 瀏覽:90
安卓怎麼關簡訊重復提醒 發布:2024-11-19 09:02:00 瀏覽:636
网站地图