我把datagrid 与数据库绑定,对datagrid中选中的数据进行删除和编辑的时候,采用以下的方法
Private Sub Cmd_del_Click()
Dim adors As New ADODb.Recordset
Dim adocon As New ADODb.Connection
Dim strCode As String
Dim c As String
adocon.CursorLocation = adUseClient
adocon.Open "provider=microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\文件编码.mdb;Persist Security Info=False"
strCode = DataGrid1.Columns(0)
adocon.Execute ("delete from 文件信息 where 文件编码 = '" + strCode + "'")
Set adors = adocon.Execute("select * from 文件信息")
Set DataGrid1.DataSource = adors
End Sub
就是先把被选中行的首列数据赋给变量strCode
再采用SQL语句再搜索定位到该项,进行删除
这方法太笨了吧
谁能告诉我怎么改
Private Sub Cmd_del_Click()
Dim adors As New ADODb.Recordset
Dim adocon As New ADODb.Connection
Dim strCode As String
Dim c As String
adocon.CursorLocation = adUseClient
adocon.Open "provider=microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\文件编码.mdb;Persist Security Info=False"
strCode = DataGrid1.Columns(0)
adocon.Execute ("delete from 文件信息 where 文件编码 = '" + strCode + "'")
Set adors = adocon.Execute("select * from 文件信息")
Set DataGrid1.DataSource = adors
End Sub
就是先把被选中行的首列数据赋给变量strCode
再采用SQL语句再搜索定位到该项,进行删除
这方法太笨了吧
谁能告诉我怎么改
解决方案 »
- 如何把一个.txt文件转换成16进制格式,象Uedit32.exe一样?
- 使用VB編寫的程序如何在裝有serv-u的ftp下通過另一臺機子使用?
- 绝对有难度的问题
- 这个是DTPicker---Bug吗
- VB的钱图在哪里???
- 哪位大哥帮帮我,怎样检测到记录集是否被锁定?用什么方发?
- 紧急求救!!!VB+远程SQL SERVER 打包问题 在线等 QQ:15709535
- 是我的书有问题,还是我的VB有问题呀,大家帮我看一下,
- 高分值的简单问题(richtextbox的应用)
- 是 如 何 在 文 本 文 件 中 查 找 指 定 字 符 并 将 其 替 换 成 别 的 字 符 ?
- 怎么分?
- 今天是2009年最后一天 散分
删除: Adodc1.Recordset.Delete
明明在datagrid中已经选择这项记录了
把执行SQL语句去查询这条记录
选中一行要删除,直接按delete键就可以了
直接在DATAGRID的KEYUP事件中(设定DEL键删除),当然用个按扭也可以
adors.delete
adors.update就可以了
2把datagrid 与数据库绑定
3运行程序,选中一行,然后按del键可删除一行。