Vb Recordset怎么回去里面的数据
PrivateSubbd()Dimcnn1AsNewADODB.ConnectionDimcomdAsNewADODB.CommandDimrsAsNewADODB.Re...
Private Sub bd()
Dim cnn1 As New ADODB.Connection
Dim comd As New ADODB.Command
Dim rs As New ADODB.Recordset
cnn1.Open "provider=sqloledb; data source=120.24.246.87,1765; initial catalog=McsCPTest_Q; user id=sa; password=mzwhgzmcs"
With comd
.ActiveConnection = cnn1 .CommandType = 4 .CommandText = "Pro_Analyse_Income_Q" .Parameters.Append .CreateParameter("@CPID", adInteger, adParamInput, 4, 9)
.Parameters.Append .CreateParameter("@IsCompanyLock", adInteger, adParamInput, 4, 0) .Parameters.Append .CreateParameter("@type", adInteger, adParamInput, 4, 0)
.Parameters.Append .CreateParameter("@SelType", adInteger, adParamInput, 4, 0) .Parameters.Append .CreateParameter("@StrWhere", adChar, adParamInput, 500, " BETWEEN '2015-01-01' and '2015-09-10' ")
End With
Set rs = comd.Execute() ‘这个数据不是回来了吗,我现在要取这里数据怎么取啊
rs.Open '这个打不开,超级恶心,vb感觉真原始,
rs.MoveFirst MsgBox rs.RecordCount
'资源释放
Set cnn1 = Nothing
Set comd = Nothing
Set rs = Nothing
End Sub
一直报 对象关闭,不允许操作。那究竟怎么打开。我在网上找不到 vb执行数据库存储例子,我自己写的。太蛋疼了,这种语言早该淘汰啊 展开
Dim cnn1 As New ADODB.Connection
Dim comd As New ADODB.Command
Dim rs As New ADODB.Recordset
cnn1.Open "provider=sqloledb; data source=120.24.246.87,1765; initial catalog=McsCPTest_Q; user id=sa; password=mzwhgzmcs"
With comd
.ActiveConnection = cnn1 .CommandType = 4 .CommandText = "Pro_Analyse_Income_Q" .Parameters.Append .CreateParameter("@CPID", adInteger, adParamInput, 4, 9)
.Parameters.Append .CreateParameter("@IsCompanyLock", adInteger, adParamInput, 4, 0) .Parameters.Append .CreateParameter("@type", adInteger, adParamInput, 4, 0)
.Parameters.Append .CreateParameter("@SelType", adInteger, adParamInput, 4, 0) .Parameters.Append .CreateParameter("@StrWhere", adChar, adParamInput, 500, " BETWEEN '2015-01-01' and '2015-09-10' ")
End With
Set rs = comd.Execute() ‘这个数据不是回来了吗,我现在要取这里数据怎么取啊
rs.Open '这个打不开,超级恶心,vb感觉真原始,
rs.MoveFirst MsgBox rs.RecordCount
'资源释放
Set cnn1 = Nothing
Set comd = Nothing
Set rs = Nothing
End Sub
一直报 对象关闭,不允许操作。那究竟怎么打开。我在网上找不到 vb执行数据库存储例子,我自己写的。太蛋疼了,这种语言早该淘汰啊 展开
展开全部
VB挺好使的,程序设计只能是多练。VB不过时,在XP编写的程序,在win7、win8上都可以用,就是某些控件不兼容而已,要不office系列为什么都使用VBA做宏程序呢?
通用模块中键入:
Public adoCon As New ADODB.Connection
Public adoRs As New ADODB.Recordset
Public Sub Main()
adoCon.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=;Data Source=自己填写"
End Sub
Function cnn() As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\a.mdb;Persist Security Info=False" ‘需要自己填写数据库名
End Function
’使用方法
‘ADODC1是VB自带的数据库控件
Adodc1.ConnectionString = cnn.ConnectionString
Dim rec
Dim i As Integer
rs.Open "select * from usertb", cnn, adOpenKeyset, adLockOptimistic
rec = rs.RecordCount
ReDim Asc(rec - 1)
rs.MoveFirst
For i = 1 To rec
’combo是下拉文本框控件
Combo.AddItem rs.Fields("名称")
Asc(i - 1) = Val(rs.Fields("密码"))
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
通用模块中键入:
Public adoCon As New ADODB.Connection
Public adoRs As New ADODB.Recordset
Public Sub Main()
adoCon.Open "Provider=MSDASQL.1;Persist Security Info=False;User ID=;Data Source=自己填写"
End Sub
Function cnn() As ADODB.Connection
Set cnn = New ADODB.Connection
cnn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & App.Path & "\a.mdb;Persist Security Info=False" ‘需要自己填写数据库名
End Function
’使用方法
‘ADODC1是VB自带的数据库控件
Adodc1.ConnectionString = cnn.ConnectionString
Dim rec
Dim i As Integer
rs.Open "select * from usertb", cnn, adOpenKeyset, adLockOptimistic
rec = rs.RecordCount
ReDim Asc(rec - 1)
rs.MoveFirst
For i = 1 To rec
’combo是下拉文本框控件
Combo.AddItem rs.Fields("名称")
Asc(i - 1) = Val(rs.Fields("密码"))
rs.MoveNext
If rs.EOF Then Exit For
Next
rs.Close
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询