㈠ 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資料庫裡面數據的增刪改查
從「工程」菜單中「引用」 引用Microsoft ActiveX data objects 2.8
private sub command_click()
Dim mycon As ADODB.Connection '定義連接資料庫對象
'如果你的資料庫是access用下面的方式打開資料庫
'*****************************************
mycon.ConnectionString = "provider= microsoft.jet.oledb.4.0;data source=" & App.Path & "/ 這里寫資料庫名.mdb"
''*****************************************
'如果你的資料庫是SQL的用下面的方式打開資料庫
'mycon.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=true;Initial Catalog=資料庫名;Data Source=.\sqlexpress"
'***************************
mycon.Open '打開資料庫
Dim rst As New ADODB.Recordset '定義一個記錄集 ,用來打開表記錄
sql="select * from information"
rst.Open Trim(SQL), mycon, adOpenKeyset, adLockOptimistic '打開記錄集
rst.addnew '添加空記錄
rst.fields(0)=text1,text
rst.fields(1)=text2,text
rst.fields(2)=text3,text
rst.fields(3)=text4,text
rst.fields(4)=text5,text
rst.update '更新資料庫
msgbox"數據錄入成功"
這樣就可以了! 不過我發現你的界面好像是VB.NET的,如果是VB.NET的你把郵箱發過來我直接過你發過去好了!
㈢ VB實現ACCESS資料庫記錄的查詢,新增,刪除,修改的代碼是什麼
「修改」按鈕的兄沖程序
Private Sub cmdEdit_Click()
sql = "select * from 停時統計 where date = cdate('" & Text8.Text & "') and ycqk = '" & Combo1.Text & "'and id = '" & DataGrid1.Columns(2).CellText(DataGrid1.Bookmark) & "滑悉'"
rs.Open sql, dm, adOpenDynamic, adLockOptimistic
rs.Fields("id") = Text7.Text
rs.Fields("ycqk") = Combo1.Text
rs.Fields("date1") = Text1.Text
rs.Fields("time1") = Text2.Text
rs.Fields("date2") = Text3.Text
rs.Fields("time2") = Text4.Text
rs.Update
rs.Close
End Sub
'「刪除」按鈕的程序
Private Sub cmdDelete_Click()
strFCode = DataGrid1.Columns(0).CellText(DataGrid1.Bookmark)
strSCode = DataGrid1.Columns(2).CellText(DataGrid1.Bookmark)
strCCode = DataGrid1.Columns(1).CellText(DataGrid1.Bookmark)
sql = "select * from 停時統計 where date='" & strFCode & "' and id='" & strSCode & "' and ycqk='" & strCCode & "'"
rs.Open sql, dm, adOpenDynamic, adLockOptimistic
rs.Delete
rs.Update
rs.Close
End Sub
'「增加」按鈕的程序
Private Sub Command1_Click()
sql = "select * from 停時信塵乎統計 order by id"
rs.Open sql, dm, adOpenDynamic, adLockOptimistic
rs.AddNew
rs.Fields("date") = Date
rs.Fields("id") = Text7.Text - 1
rs.Fields("ycqk") = Combo1.Text
rs.Fields("date1") = Text1.Text
rs.Fields("time1") = Text2.Text
rs.Fields("date2") = Text3.Text
rs.Fields("time2") = Text4.Text
rs.Update
rs.Close
With Adodc1
Adodc1.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\db1.mdb;Persist Security Info=False"
Adodc1.RecordSource = "select * from 停時統計 where date = cdate('" & Text8.Text & "') and ycqk = '" & Combo1.Text & "' order by id"
Adodc1.Refresh
DataGrid1.Refresh
End With
End Sub
㈣ 誰能給我vb對sql資料庫進行新增,刪除,查詢,修改的代碼
連接資料庫 直接用 sql語句就能進行了啊querysql1 = "select * from book1 where 檔案號 like '%" & Text1.Text & "%'"rs.Open str, conn, adOpenDynamic, adLockPessimistic
conn.Execute str返回到是rs結果集addstr = "select * from book1 "
rs.Open str, conn, adOpenDynamic, adLockPessimistic
conn.Execute str
rs.AddNew
rs("id") = id
rs("name") = name
rs.Updateupdatestr = "update book1 set name='" & Text2.Text & "'where id= '" & idh & "'"
rs.Open str, conn, adOpenDynamic, adLockPessimistic
conn.Execute strdelstr = "Delete from book11 where id ='" & Label8.Caption & "'"
rs.Open str, conn, adOpenDynamic, adLockPessimistic
conn.Execute str