Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1666
  • Last Modified:

Nvarchar overflowed an int column

In one of my Access form's event codes is the following:

Dim rs1 As ADODB.Recordset
Dim strCriteria1 As String
Dim strCriteria2 As String

Set rs1 = New ADODB.Recordset
strCriteria1 = Me.EbayNum
strCriteria2 = Me.Parent.OrderID

rs1.Open "SELECT * FROM dbo.[ORDER-DETAIL] WHERE dbo.[ORDER-DETAIL].EbayNum = " & strCriteria1 & " AND dbo.[ORDER-DETAIL].OrderID = " & strCriteria2, CurrentProject.Connection
............

Me.EbayNum refers to a control that is bound to an underlying SQL table where EbayNum is of type nvarchar(20).

The code runs when I enter an EbayNum value into a subform. As I enter subsequent EbayNums, the code runs fine -- UNLESS one of the two following things happens:

1) I enter an EbayNum that is shorter than the longest EbayNum value already in the subform
2) I enter an EbayNum that is as long as the longest EbayNum value, but is of lesser numerical value

Then, I'll get one or the other of these errors:

1)"Runtime error '-2147217833 (80040e57)': Arithmetic overflow error converting numeric to data type numeric."
2)"Runtime error '-2147217833 (80040e57)': The conversion of the nvarchar value <last value in the list> overflowed an int column. Maximum integer value exceeded."

Either error occurs on the rs1.open statement. Can anyone shed some light? Why is 'int' even involved in this?





0
Galisteo8
Asked:
Galisteo8
  • 2
1 Solution
 
pelegstCommented:
I think the reason "int" is involved is that there appears to be an implicit type conversion going on. It is taking your strings, strCriteria1 or strCriteria2, and converting it to integers because you haven't quoted the strings in your Select. First, I'd try adding quotes as follows:

rs1.Open "SELECT * FROM dbo.[ORDER-DETAIL] WHERE dbo.[ORDER-DETAIL].EbayNum = '" & strCriteria1 & "' AND dbo.
                                                                                                                                    ^                        ^
                                                                                                                                    ' "                      ' "               
[ORDER-DETAIL].OrderID = '" & strCriteria2 & "'", CurrentProject.Connection
                                                                    ^
                                                                    " ' "
The need not be spaces around the quotes, but below the ^ I showed them with blanks so it would be clear about how to quote them.

One more thing. It is not necessary to store the controls in a string and then use then in the Select; it is actually redundant. Just remember that controls act like variant variables when you use them directly. So, you could have writtten:

rs1.Open "SELECT * FROM dbo.[ORDER-DETAIL] WHERE dbo.[ORDER-DETAIL].EbayNum = '" & Me.EbayNum & "' AND dbo.[ORDER-DETAIL].OrderID = '" & Me.Parent.OrderID & "'", CurrentProject.Connection


0
 
Galisteo8Author Commented:
<slapping forehead> The quotes!  I've been out of the office for a week - I KNEW I was forgetting something.

Also, I've tended to get into the habit of using these string variables in larger, more complex events, but I agree it is not necessary here.

Anyway, I'll give this a go tomorrow (hopefully) and report back.
0
 
Galisteo8Author Commented:
The mathematics-related errors have ceased. Thanks!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now