当前位置:首页 » 编程语言 » vb怎么对sql增删改查
扩展阅读
webinf下怎么引入js 2023-08-31 21:54:13
堡垒机怎么打开web 2023-08-31 21:54:11

vb怎么对sql增删改查

发布时间: 2023-07-22 19:07:41

㈠ 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