[英]Type Mismatch error 13 in vb6, during ADODB Recordset loop
Private Sub cmdShow_Click()
'lblTotPur/lblTotPayRet/lblBalance
Dim strShow, mSlNo
Dim rsShow As New ADODB.Recordset
Dim NewItem As Variant
If Trim(txtCustomer.Text) = "" Then
MsgBox "Please select vendor to proceed...", vbCritical, POPUP_COMP
Exit Sub
End If
Dim recCnt
pgrPartyLedger.Min = 0
recCnt = 0
'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser CASH PURCHASE RETURN
strShow = "select Count(*) as mCnt from VOUCHMST A,VOUCHDAT B, mPurchase C "
strShow = strShow & " where A.VNO=B.VNO and (A.REMARKS='CASH PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE' OR A.REMARKS='CASH PURCHASE' OR A.REMARKS='PAYMENT' OR A.REMARKS='CREDIT NOTE') "
strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
strShow = strShow & " and A.VREFNO = C.PurBillNo "
'strShow = strShow & " order by A.ID,A.DATED,A.VNO"
rsShow.Open strShow, cn
recCnt = rsShow("mCnt")
rsShow.Close
pgrPartyLedger.Max = recCnt + 1
'VOUCHMST_P//VNO,DATED,VTYPE,REMARKS,byUser
strShow = "select A.Id,A.cmnt,A.VNO,A.DATED,B.IDNO,B.IDNAME,B.AMOUNT,B.DR_CR,B.VNARRATION,A.REMARKS,C.DealInvNo, B.CQ_TYPE, B.BANKNAME, B.BANKBRANCH, B.CQ_NO from VOUCHMST A,VOUCHDAT B,mPurchase C "
strShow = strShow & " where A.VNO=B.VNO and (A.REMARKS='CASH PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE RETURN' OR A.REMARKS='CREDIT PURCHASE' OR A.REMARKS='CASH PURCHASE' OR A.REMARKS='PAYMENT' OR A.REMARKS='CREDIT NOTE') "
strShow = strShow & " and A.DATED between #" & Format(dtFrom.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and #" & Format(dtTo.Value, "MM/dd/yyyy") & "# "
strShow = strShow & " and B.IDNO = '" & Trim(txtCustomerId.Text) & "' "
strShow = strShow & " and A.VREFNO = C.PurBillNo "
strShow = strShow & " order by A.ID,A.DATED,A.VNO"
rsShow.Open strShow, cn
Dim mPur, mPayRet, mAnyAdv, mTempVNO
mPur = 0
mPayRet = 0
mAnyAdv = 0
mSlNo = 1
ShowPaymentHeader
Do While Not rsShow.EOF
mTempVNO = rsShow("VNO")
Set NewItem = listViewPayment.ListItems.Add(, "C" & mSlNo, Format(rsShow("DATED"), "dd/MM/yyyy"))
NewItem.SubItems(1) = rsShow("VNO")
NewItem.SubItems(13) = rsShow("DealInvNo")
NewItem.SubItems(2) = IIf(IsNull(rsShow("IDNAME")), "", CommaFilterText(rsShow("IDNAME"), 1))
If Trim(rsShow("REMARKS")) = "CASH PURCHASE" Then
NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT"))
NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
ElseIf Trim(rsShow("REMARKS")) = "CREDIT PURCHASE" Then
mAnyAdv = ShowPartialAdvance(rsShow("VNO"))
NewItem.SubItems(3) = FormatTakaPaisa(rsShow("AMOUNT") + Val(mAnyAdv))
If Val(mAnyAdv) > 0 Then
NewItem.SubItems(4) = FormatTakaPaisa(mAnyAdv)
Else
NewItem.SubItems(4) = ""
End If
Else
NewItem.SubItems(3) = ""
NewItem.SubItems(4) = FormatTakaPaisa(rsShow("AMOUNT"))
NewItem.SubItems(7) = rsShow("CQ_TYPE")
NewItem.SubItems(8) = rsShow("BANKNAME")
NewItem.SubItems(9) = rsShow("BANKBRANCH")
**
> NewItem.SubItems(9) = rsShow("cmnt")
**
End If
NewItem.SubItems(6) = rsShow("IDNO")
mPur = mPur + Val(NewItem.SubItems(3))
mPayRet = mPayRet + Val(NewItem.SubItems(4))
NewItem.SubItems(5) = rsShow("REMARKS")
NewItem.SubItems(12) = GetVoucherRefNo(mTempVNO)
pgrPartyLedger.Value = mSlNo
mSlNo = mSlNo + 1
rsShow.MoveNext
Loop
rsShow.Close
lblTotPur.Caption = FormatTakaPaisa(mPur)
lblTotPayRet.Caption = FormatTakaPaisa(mPayRet)
lblBalance.Caption = FormatTakaPaisa(mPur - mPayRet)
pgrPartyLedger.Value = 0
End Sub
I am getting type mismatch runtime error 13 for that line, Please help me我收到该行的类型不匹配运行时错误 13,请帮助我
Depending from your database design and from your query, you may have fields with null values or fields with zero-length strings.根据您的数据库设计和查询,您可能有空值字段或零长度字符串字段。 You should always check for this especially when you do outer joins, or multiple joins like in your query.
您应该始终检查这一点,尤其是在执行外部联接或查询中的多个联接时。
If you check the content of just only of a table and you see the fields are all populated, this doesn't mean the resulting set will return only valid values - but this goes beyond the scope of this answer.如果您只检查一个表的内容并且您看到所有字段都已填充,这并不意味着结果集将仅返回有效值 - 但这超出了本答案的范围。
There are multiple common practices to check Field values and trap errors when dealing with a Recordset.在处理 Recordset 时,有多种常见的做法来检查字段值和捕获错误。 Just to name a few:
仅举几个:
On Error Resume ...
blocks: avoid this, you haven't an overview of what's happen On Error Resume ...
blocks: 避免这种情况,你没有对发生的事情有一个概览Check for Null
values, DBNull
values, Empty
values or check the Field Type
.检查
Null
值、 DBNull
值、 Empty
值或检查Field Type
。 Just one example:举个例子:
If IsNull(rsShow("cmnt").value) = True Then NewItem.SubItems(9) = "" Else NewItem.SubItems(9) = rsShow("cmnt") End If
Note: you should explicit the value
property of the Field.注意:您应该明确 Field 的
value
属性。
If you do Field Type check, learn to use the Object Browser integrated in the VB IDE, this will your best friend.如果您进行字段类型检查,学习使用集成在 VB IDE 中的对象浏览器,这将是您最好的朋友。
Check the ActualSize
property of the Field: see MSDN: The Field Object检查字段的
ActualSize
属性:请参阅 MSDN: 字段对象
Another common shortcut is to prepend or append a string with zero-length to the return value of the Field, this is only valid if you don't have to distinguish between Null
values and Blank
values and you just only need to show the result in a label or in a list, as your case is: NewItem.SubItems(9) = "" & rsShow("cmnt")
另一个常见的快捷方式是在 Field 的返回值中添加或附加一个长度为零的字符串,这仅在您不必区分
Null
值和Blank
值并且您只需要显示结果时才有效标签或列表,根据您的情况: NewItem.SubItems(9) = "" & rsShow("cmnt")
About Error 13
: In the VB IDE, open the Immediate Window
, type in: ? 0 = ""
关于
Error 13
:在 VB IDE 中,打开Immediate Window
,输入: ? 0 = ""
? 0 = ""
and then press Enter. ? 0 = ""
然后按 Enter。 What is the result?结果是什么?
Last but not least, always double-check the names of the fields, each database developer has been faced with errors due to typos, notably when dealing with financial applications with dozens of tables and hundreds of fields.最后但并非最不重要的一点是,始终仔细检查字段的名称,每个数据库开发人员都曾因拼写错误而面临错误,尤其是在处理具有数十个表和数百个字段的金融应用程序时。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.