vb6.0用command控件删除datagrid中的一行数据?
我的程序:PrivateSubCommand1_Click()'查询DimcnAsNewADODB.Connection'定义一个数据库对象Dimst0AsNewADOD...
我的程序:
Private Sub Command1_Click() '查询Dim cn As New ADODB.Connection '定义一个数据库对象Dim st0 As New ADODB.Recordset '定义一个stordest对象Dim sl As String cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=xiewei;Data Source=PC-20110605TMUI" sl = "select * from xwuser " st0.Open sl, cn, adOpenKeyset, adLockOptimistic Set DataGrid1.DataSource = st0End Sub
Private Sub Command2_Click() '删除
st0.Deletest0.UpdateDataGrid1.Refresh
End Sub 展开
Private Sub Command1_Click() '查询Dim cn As New ADODB.Connection '定义一个数据库对象Dim st0 As New ADODB.Recordset '定义一个stordest对象Dim sl As String cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=xiewei;Data Source=PC-20110605TMUI" sl = "select * from xwuser " st0.Open sl, cn, adOpenKeyset, adLockOptimistic Set DataGrid1.DataSource = st0End Sub
Private Sub Command2_Click() '删除
st0.Deletest0.UpdateDataGrid1.Refresh
End Sub 展开
2个回答
展开全部
你的变量名st0是在Command1_Click()里声明的,那么在Command2_Click()里如何能够识别?
修改如下:
Private st0 As New ADODB.Recordset '定义一个stordest对象
Private Sub Command1_Click() '查询
Dim cn As New ADODB.Connection '定义一个数据库对象
Dim sl As String
cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=xiewei;Data Source=PC-20110605TMUI"
sl = "select * from xwuser "
st0.Open sl, cn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = st0
End Sub
Private Sub Command2_Click() '删除
st0.Delete
DataGrid1.Refresh
End Sub
说明:删除记录并不需要
st0.Update
修改如下:
Private st0 As New ADODB.Recordset '定义一个stordest对象
Private Sub Command1_Click() '查询
Dim cn As New ADODB.Connection '定义一个数据库对象
Dim sl As String
cn.Open "Provider=SQLOLEDB.1;Persist Security Info=False;User ID=sa;Initial Catalog=xiewei;Data Source=PC-20110605TMUI"
sl = "select * from xwuser "
st0.Open sl, cn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = st0
End Sub
Private Sub Command2_Click() '删除
st0.Delete
DataGrid1.Refresh
End Sub
说明:删除记录并不需要
st0.Update
展开全部
If DataGrid1.ColIndex > -1 Then
DataGrid1.Bookmark
End If
DataGrid1.Bookmark
End If
更多追问追答
追答
注意这个DataGrid1.ColIndex
d=datagrid1.colindex
sl="select * from xwuser where xxx='" & datagrid1.TextMatrix(xx, 4) & "xxx='" & datagrid1.TextMatrix(xx, 3) & "'"
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询