我想删除表里的内容,怎么删那?我是这么写的,不好使啊!Dim intcount As Integer
intcount = MSFlexGrid1.Row
rs.Open "select * from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'", db, adOpenStatic, adLockReadOnly
rs.Close
Private Sub 删除_Click()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "driver={SQL Server};server=DAHE-568D57C089;database=歌库;"
db.Open
rs.Open "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'", db, adOpenStatic, adLockReadOnly MsgBox "删除成功!", vbInformation, "提醒"
End Sub
intcount = MSFlexGrid1.Row
rs.Open "select * from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'", db, adOpenStatic, adLockReadOnly
rs.Close
Private Sub 删除_Click()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "driver={SQL Server};server=DAHE-568D57C089;database=歌库;"
db.Open
rs.Open "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'", db, adOpenStatic, adLockReadOnly MsgBox "删除成功!", vbInformation, "提醒"
End Sub
===============================
正确的写法是:
db.execute "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'"
db.execute "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'"
两个条件是相同的格子,但是对应的字段取不一样!
Private Sub 删除_Click()
ADODC.Recordset.Delete
'或 rs.Delete
End Sub否则:
Private Sub 删除_Click()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "driver={SQL Server};server=DAHE-568D57C089;database=歌库;"
db.Open
db.Execute "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 0)) & "'and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)) & "'"
'注意,歌曲名和歌手名所比较的网格单元必须正确,原来都是TextMatrix(x, 1),所以执行结果是没有记录被删掉。MsgBox "删除成功!", vbInformation, "提醒"
End Sub
'或 rs.Delete这个说得很正确
intcount = MSFlexGrid1.Row
rs.open "select * from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'", db, adOpenStatic, adLockReadOnly
rs.Close
Private Sub 删除_Click()
Set db = New ADODB.Connection
Set rs = New ADODB.Recordset
db.ConnectionString = "driver={SQL Server};server=DAHE-568D57C089;database=歌库;"
db.Open
db.Execute "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "' and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'"
'----->and前面要空格,还有用adLockReadOnly是只读的,也就删不了!还有你的intcount变量是窗体变量吗?还是在另一个过程里定义的? MsgBox "删除成功!", vbInformation, "提醒"
End Sub附上:
rs.open后的相关参数adOpenFowardOnly。使用前向游标,你只能在记录集中向前移动。
adopenKeyset。使用Keyset游标,你可以在记录集中向前或向后移动。如果另一个用户删除或改变了一条记录,记录集中将反映这个变化。但是,如果另一个用户添加了一条新记录,新记录不会出现在记录集中。
adOpenDynamic。使用动态游标,你可以在记录集中向前或向后移动。其他用户造成的记录的任何变化都将在记录集中有所反映。
adOpenStatic。使用静态游标,你可以在记录集中向前或向后移动。但是,静态游标不会对其他用户造成的记录变化有所反映。
---------------------------------------------------------------
adLockReadOnly。指定你不能修改记录集中的记录。
adLockPessimistic。指定在编辑一个记录时,立即锁定它。
adLockOptimstic。指定只有调用记录集的Update方法时,才锁定记录。
adLockBatchOptimstic。指定记录只能成批地更新。
先看sql对不
Set db = New ADODb.Connection
Set Rs = New ADODb.Recordset
db.ConnectionString = "driver={SQL Server};server=DAHE-568D57C089;database=歌库;"
db.Open
Rs.Open "select * from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(intcount, 1)) & "'", db, adOpenStatic, adLockReadOnly
Rs.Close
db.Execute "delete from yixuan where 歌曲名 ='" & Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 1)) & "' and 歌手名 = '" & Trim(MSFlexGrid1.TextMatrix(MSFlexGrid1.Row, 2)) & "'"
MsgBox "删除成功!", vbInformation, "提醒"
End Sub