在vb编程中怎样查询sql数据库中某一个区间的数据并把记录条数返回给vb程序的变量
1个回答
展开全部
Private RecSet1 As New Recordset
Dim sSql As String
sSql = " SELECT* FROM Table WHERE MainID='" & MainID & "'" & _
" UNION " & _
" SELECT MainID, Name, VipID, Sex, Birth, MPhone, Phone, Addr, BDate, CardID, BCoID, BPosID, UmType, UmDiscount, UpdateTime,State, CASE WHEN State=0 THEN '未提交' ELSE '已提交' END AS StateName FROM UserInfo WHERE MainId NOT IN(SELECT MainID FROM UserInfo2 WHERE MainID='" & MainID & "') AND MainID='" & MainID & "'"
If RecSet1.State = adStateOpen Then RecSet1.Close
RecSet1.Open sSql, adoconn
If Not (RecSet1.BOF) And Not (RecSet1.EOF) Then
Me.txtCusId.text = MainID
Me.txtCusName.text = Trim(RecSet1!Name) '会员姓名
Me.TxtDel.text = Trim(RecSet1!UmDiscount) '折扣
Else
Me.txtCusId.text = ""
Me.txtCusName.text = ""
Me.TxtDel.text = "1"
End If
Dim sSql As String
sSql = " SELECT* FROM Table WHERE MainID='" & MainID & "'" & _
" UNION " & _
" SELECT MainID, Name, VipID, Sex, Birth, MPhone, Phone, Addr, BDate, CardID, BCoID, BPosID, UmType, UmDiscount, UpdateTime,State, CASE WHEN State=0 THEN '未提交' ELSE '已提交' END AS StateName FROM UserInfo WHERE MainId NOT IN(SELECT MainID FROM UserInfo2 WHERE MainID='" & MainID & "') AND MainID='" & MainID & "'"
If RecSet1.State = adStateOpen Then RecSet1.Close
RecSet1.Open sSql, adoconn
If Not (RecSet1.BOF) And Not (RecSet1.EOF) Then
Me.txtCusId.text = MainID
Me.txtCusName.text = Trim(RecSet1!Name) '会员姓名
Me.TxtDel.text = Trim(RecSet1!UmDiscount) '折扣
Else
Me.txtCusId.text = ""
Me.txtCusName.text = ""
Me.TxtDel.text = "1"
End If
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询