VB6程序adodb如何获取DataGrid选中行的值显示到另一窗口中。现在一直显示首行数据。
PrivateSubCmdList_Click()frmMain.Hide'判断是否选择了表中的一行Setrs1.ActiveConnection=cnnIfrs1.St...
Private Sub CmdList_Click()
frmMain.Hide
'判断是否选择了表中的一行
Set rs1.ActiveConnection = cnn
If rs1.State <> adStateClosed Then rs1.Close
rs1.Open "select * from users", cnn, adOpenKeyset, adLockOptimistic
If rs1.EOF = True Or rs1.BOF = True Then
MsgBox "请选择要显示的行"
Exit Sub
End If
'读取数据
FrmShowData.Text1 = rs1.Fields(0)
If rs1.Fields(1) <> "" Then
FrmShowData.Text2 = rs1.Fields(1)
Else
FrmShowData.Text2 = ""
End If
If rs1.Fields(2) <> "" Then
FrmShowData.Text3 = rs1.Fields(2)
Else
FrmShowData.Text3 = ""
End If
'打开显示数据窗口
FrmShowData.Show 1
End Sub
Private Sub Form_Load()
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\userman.mdb"
If rs1.State <> adStateClosed Then rs1.Close
rs1.CursorLocation = adUseClient
rs1.Open "select * from users", cnn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rs1
End Sub
模块
Public cnn As New ADODB.Connection '牢记最后要用到 cnn.Close
Public cmd As New ADODB.Command
Public rs1 As New ADODB.Recordset
Public rs2 As New ADODB.Recordset 展开
frmMain.Hide
'判断是否选择了表中的一行
Set rs1.ActiveConnection = cnn
If rs1.State <> adStateClosed Then rs1.Close
rs1.Open "select * from users", cnn, adOpenKeyset, adLockOptimistic
If rs1.EOF = True Or rs1.BOF = True Then
MsgBox "请选择要显示的行"
Exit Sub
End If
'读取数据
FrmShowData.Text1 = rs1.Fields(0)
If rs1.Fields(1) <> "" Then
FrmShowData.Text2 = rs1.Fields(1)
Else
FrmShowData.Text2 = ""
End If
If rs1.Fields(2) <> "" Then
FrmShowData.Text3 = rs1.Fields(2)
Else
FrmShowData.Text3 = ""
End If
'打开显示数据窗口
FrmShowData.Show 1
End Sub
Private Sub Form_Load()
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + App.Path + "\userman.mdb"
If rs1.State <> adStateClosed Then rs1.Close
rs1.CursorLocation = adUseClient
rs1.Open "select * from users", cnn, adOpenKeyset, adLockOptimistic
Set DataGrid1.DataSource = rs1
End Sub
模块
Public cnn As New ADODB.Connection '牢记最后要用到 cnn.Close
Public cmd As New ADODB.Command
Public rs1 As New ADODB.Recordset
Public rs2 As New ADODB.Recordset 展开
1个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询