nvarchar value overflowed an integer column error

Moordoom

Member
Joined
Nov 12, 2013
Messages
23
Programming Experience
1-3
Ok, My code was work all fine and dandy when we used customer number that were numerical in value. We moved some customers from another office into our database, and the customer number are alpha characters...

Now every time I run this code I get "The conversion of the nvarchar value ' 4000545398' overflowed an int column. Maximum integer value exceeded."
Code as follows...

VB.NET:
[FONT=Consolas][SIZE=2][FONT=Consolas][SIZE=2]' Get Customer NameUsing connObj2 As New SqlClient.SqlConnection("server=Server;database=App;uid=sa;pwd=password;")
    Using cmdObj2 As New SqlClient.SqlCommand("SELECT c2.name, c2.cust_num from custaddr as c2 INNER JOIN co as c1 ON (c2.cust_num = c1.cust_num) INNER JOIN shipper as s1 on (c1.co_num = s1.co_num) WHERE c2.cust_seq = 0 AND lot = " & Carton1, connObj2)
        connObj2.Open()
        Using readerObj2 As SqlClient.SqlDataReader = cmdObj2.ExecuteReader
            'This will loop through all returned records 
            While readerObj2.Read
                dbCustNum = readerObj2("cust_num").ToString
                dbCustName = readerObj2("name").ToString
                'handle returned value before next loop here
            End While
        End Using
        connObj2.Close()
    End Using
End Using
[/SIZE][/FONT][/SIZE][/FONT]

My error comes at 'While readerObj2.Read'.
When I set around it in debug, It says it "expects a value for dbCustName".
my declarations are
VB.NET:
Dim dbCustName As String
Dim dbCustNum As String
Could not decide if it should go in this forum group or SQL...
Sorry if I posted to the wrong group.
 
Why is a conversion from nvarchar to int taking place in the first place? I can only assume that one of your joins is being done on columns of different types. Is that the case?
 
name and cust_num in custaddr are nvarchar(50) and co_num in shipper_sii is nvarchar(10). cust_seq is int(4)...
I guess now I have to see the ramifications of changing that column to nvarchar....
Thanks for the help :)
 
Fighting with it, It ended up being a corrupted record.
Went to the record in Studio Management, and retyped in the lot number 4000545398 for that particular record, and everything is working now.
 
Back
Top