急急急!SQLserver通过adodb连接问题,大神进

With Adodc1.Recordset
If .RecordCount > 0 Then
Do While .EOF = False
View_tfdata
.MoveNext
Loop
End If
End With
如何把此段代码改成用ADODB

4个回答

Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql1 As String
Dim sql2 As String
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MZJJSFXT;Data Source=."
cn.Open
sql1 = "select 结算方式 as 收款方式,count(收据号)as 收据数,sum(总金额)as 金额 from 收费单据信息表 where 操作员='" + Txtsky.Text + "'and 收据号 between '" + Txtsjn1.Text + "'And '" + Txtsjn2.Text + "'group by 结算方式"
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
rs.Open sql1, cn, adOpenKeyset, adLockOptimistic
With rs
If rs.RecordCount > 0 Then
Do While rs.EOF = False
View_sfdata
rs.MoveNext
Loop
End If
End With
rs.Close
Set rs = Nothing

//打开一个结果集
p_RecordSetPtr->Open(_bstr_t(sqlcmd.c_str()), m_pConnection.GetInterfacePtr(), adOpenForwardOnly, adLockReadOnly, adCmdText);
//判断是否为空
while (!p_RecordSetPtr->adoEOF)
{
//根据字段取值
_variant_t va = p_RecordSetPtr->GetCollect(field);
//根据值的类型不同,取对应的值,建议去看看 _variant_t 这个数据类型。
switch (va.vt)
{

                    }
                    //移动到下一条
                p_RecordSetPtr->MoveNext();
            }
qq_38486475
尼莫和可爱多 请问这是VB能识别的吗
大约 2 年之前 回复

这代码需要改吗? 不是用的 ADODB.Connection 和 ADODB.RecordSet 吗?

qq_38486475
尼莫和可爱多 Do While ADODB.EOF = False这句打错了,是Do While .EOF = False。想问怎么能不用到adodc属性连接直接用代码
大约 2 年之前 回复

可以了,问题已经解决了
Dim cn As New ADODB.Connection
Dim rs As New ADODB.Recordset
Dim sql1 As String
Dim sql2 As String
cn.ConnectionString = "Provider=SQLOLEDB.1;Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=MZJJSFXT;Data Source=."
cn.Open
sql1 = "select 结算方式 as 收款方式,count(收据号)as 收据数,sum(总金额)as 金额 from 收费单据信息表 where 操作员='" + Txtsky.Text + "'and 收据号 between '" + Txtsjn1.Text + "'And '" + Txtsjn2.Text + "'group by 结算方式"
If rs.State = adStateOpen Then rs.Close
rs.CursorLocation = adUseClient
rs.Open sql1, cn, adOpenKeyset, adLockOptimistic
With rs
If rs.RecordCount > 0 Then
Do While rs.EOF = False
View_sfdata
rs.MoveNext
Loop
End If
End With
rs.Close
Set rs = Nothing

Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问