Integer VB Vrs Integer SQL Arrrgggggggg 
Author Message
 Integer VB Vrs Integer SQL Arrrgggggggg

Why ?

An sql counter field is Int by default normaly this would be used but in vb
Integer is limited so when retriving data in vb based on the counter id in
sql we blow-up. With a nice

"Runtime error 6 Overflow"

SQL Data Type Interger "integer or int Has a length of 4 bytes, and stores
numbers from -2,147,483,648 through 2,147,483,647"

VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

Does MS have A standard or what ???

Am i now forced to chage all integer variables in my code to long?

Or is there a solution here?

Any input all

Jason



Fri, 26 Mar 2004 23:11:09 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
When asking for an SQL integer in VB or Access, you wil have to refer to it
as a long. I don't have any other solution.

HTH

Del at Equisoft



Fri, 26 Mar 2004 23:43:42 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
There is no other solution; SQL Server is designed according (for the most
part) to the ANSI SQL92 standard, which dictates the standards for data
types. Visual Basic, on the other hand, inherits its types from our early
BASIC compilers to maintain backward compatibility.

Steven Bras, MCSD
Microsoft Developer Support/Visual Basic WebData

This posting is provided "AS IS" with no warranties, and confers no rights.
You assume all risk for your use. ? 2001 Microsoft Corporation. All rights
reserved.



Sat, 27 Mar 2004 05:35:16 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
Ok thanks all

jason



Quote:
> Why ?

> An sql counter field is Int by default normaly this would be used but in
vb
> Integer is limited so when retriving data in vb based on the counter id in
> sql we blow-up. With a nice

> "Runtime error 6 Overflow"

> SQL Data Type Interger "integer or int Has a length of 4 bytes, and stores
> numbers from -2,147,483,648 through 2,147,483,647"

> VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> Does MS have A standard or what ???

> Am i now forced to chage all integer variables in my code to long?

> Or is there a solution here?

> Any input all

> Jason



Sat, 27 Mar 2004 15:10:01 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
Such is life. There are many instances where you might get bitten using a VB
int. I tend to use long pretty much by default these days. It should be a
more efficient data type on a modern PC, anyway. As for SQL and VB having
different definitions of integer, it's not really down to MS - they're both
different languages. VB.Net uses 32 bit integer, by the way.

Kev


Quote:
> Why ?

> An sql counter field is Int by default normaly this would be used but in
vb
> Integer is limited so when retriving data in vb based on the counter id in
> sql we blow-up. With a nice

> "Runtime error 6 Overflow"

> SQL Data Type Interger "integer or int Has a length of 4 bytes, and stores
> numbers from -2,147,483,648 through 2,147,483,647"

> VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> Does MS have A standard or what ???

> Am i now forced to chage all integer variables in my code to long?

> Or is there a solution here?

> Any input all

> Jason



Sat, 27 Mar 2004 16:09:55 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
I think that we have all learnt this lesson. Unfortunately, VB will cast a
Long to Integer if it is small enough, so there will be a number of apps out
there that have the bug but have not yet exposed it with real values.

Peter


Quote:
> Why ?

> An sql counter field is Int by default normaly this would be used but in
vb
> Integer is limited so when retriving data in vb based on the counter id in
> sql we blow-up. With a nice

> "Runtime error 6 Overflow"

> SQL Data Type Interger "integer or int Has a length of 4 bytes, and stores
> numbers from -2,147,483,648 through 2,147,483,647"

> VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> Does MS have A standard or what ???

> Am i now forced to chage all integer variables in my code to long?

> Or is there a solution here?

> Any input all

> Jason



Sat, 27 Mar 2004 18:45:28 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
Could you explain what you mean by:
"Unfortunately, VB will cast a Long to Integer if it is small enough"


Quote:
> I think that we have all learnt this lesson. Unfortunately, VB will cast a
> Long to Integer if it is small enough, so there will be a number of apps
out
> there that have the bug but have not yet exposed it with real values.

> Peter



> > Why ?

> > An sql counter field is Int by default normaly this would be used but in
> vb
> > Integer is limited so when retriving data in vb based on the counter id
in
> > sql we blow-up. With a nice

> > "Runtime error 6 Overflow"

> > SQL Data Type Interger "integer or int Has a length of 4 bytes, and
stores
> > numbers from -2,147,483,648 through 2,147,483,647"

> > VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> > Does MS have A standard or what ???

> > Am i now forced to chage all integer variables in my code to long?

> > Or is there a solution here?

> > Any input all

> > Jason



Sat, 27 Mar 2004 19:51:55 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
He means that the value returned from SQL Server is a long, even though it
will often have a value that will fit in 16 bits.. Eg, if SQL returns
0x00000100, VB will decide it is safe to cast this to 0x0100 since no
information is lost. If SQL returns 0x00010100 though, you will get an
overflow error.


Quote:
> Could you explain what you mean by:
> "Unfortunately, VB will cast a Long to Integer if it is small enough"



> > I think that we have all learnt this lesson. Unfortunately, VB will cast
a
> > Long to Integer if it is small enough, so there will be a number of apps
> out
> > there that have the bug but have not yet exposed it with real values.

> > Peter



> > > Why ?

> > > An sql counter field is Int by default normaly this would be used but
in
> > vb
> > > Integer is limited so when retriving data in vb based on the counter
id
> in
> > > sql we blow-up. With a nice

> > > "Runtime error 6 Overflow"

> > > SQL Data Type Interger "integer or int Has a length of 4 bytes, and
> stores
> > > numbers from -2,147,483,648 through 2,147,483,647"

> > > VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> > > Does MS have A standard or what ???

> > > Am i now forced to chage all integer variables in my code to long?

> > > Or is there a solution here?

> > > Any input all

> > > Jason



Sat, 27 Mar 2004 21:08:15 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
Try this code:

Private Sub Form_Load()
Dim MyInt As Integer
Dim MyLong As Long
    On Error Resume Next
    MyLong = 1
    MyInt = MyLong    'There is no error because the value '1' can be stored
in an Integer
    If Err.Number <> 0 Then
        MsgBox Err.Description
    End If
    MyLong = 35000
    MyInt = MyLong    'We get the overflow error now because the value 35000
cannot be assigned to an Integer
    If Err.Number <> 0 Then
        MsgBox Err.Description
    End If
End Sub

Peter


Quote:
> Could you explain what you mean by:
> "Unfortunately, VB will cast a Long to Integer if it is small enough"



> > I think that we have all learnt this lesson. Unfortunately, VB will cast
a
> > Long to Integer if it is small enough, so there will be a number of apps
> out
> > there that have the bug but have not yet exposed it with real values.

> > Peter



> > > Why ?

> > > An sql counter field is Int by default normaly this would be used but
in
> > vb
> > > Integer is limited so when retriving data in vb based on the counter
id
> in
> > > sql we blow-up. With a nice

> > > "Runtime error 6 Overflow"

> > > SQL Data Type Interger "integer or int Has a length of 4 bytes, and
> stores
> > > numbers from -2,147,483,648 through 2,147,483,647"

> > > VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> > > Does MS have A standard or what ???

> > > Am i now forced to chage all integer variables in my code to long?

> > > Or is there a solution here?

> > > Any input all

> > > Jason



Sun, 28 Mar 2004 16:11:21 GMT  
 Integer VB Vrs Integer SQL Arrrgggggggg
However, I am very happy I learned of this problem with test data, before
releasing the product...

thanks again all

jason



Quote:
> I think that we have all learnt this lesson. Unfortunately, VB will cast a
> Long to Integer if it is small enough, so there will be a number of apps
out
> there that have the bug but have not yet exposed it with real values.

> Peter



> > Why ?

> > An sql counter field is Int by default normaly this would be used but in
> vb
> > Integer is limited so when retriving data in vb based on the counter id
in
> > sql we blow-up. With a nice

> > "Runtime error 6 Overflow"

> > SQL Data Type Interger "integer or int Has a length of 4 bytes, and
stores
> > numbers from -2,147,483,648 through 2,147,483,647"

> > VB Data Type Integer "Integer 2 bytes -32,768 to 32,767 "

> > Does MS have A standard or what ???

> > Am i now forced to chage all integer variables in my code to long?

> > Or is there a solution here?

> > Any input all

> > Jason



Mon, 29 Mar 2004 15:26:34 GMT  
 
 [ 10 post ] 

 Relevant Pages 

1. Sub Form_QueryUnload(Cancel As Integer, UnloadMode As Integer)

2. Converting integers and long integers to byte arrays

3. Long = Integer * Integer Overflow error

4. Integer or "integer"??

5. How do you use new Bitmap(Integer,Integer,Integer,PixelFormat,IntPtr)?

6. regular expression for sql server integer

7. Long Integers and SQL Query Probs

8. SQL: CREATE TABLE tbl ([Name] Integer)

9. SQL: increment integer field

10. Convert String to Integer in VBScript to SQL

11. CR8 returning incorrect Integer Problems from SQL

12. including Integer and Single variables in SQL SELECT

 

 
Powered by phpBB® Forum Software