assigning a string to a string variable throwing Arithmetic operation resulted in an overflow,

142 views Asked by At

While processing the following code am getting some error.

queryCommand= "select user_name,user_lastname,user_address from usertable"
objODBCDataReader = dbconObject.GetDataReader(queryCommand)
If objODBCDataReader.HasRows = True Then
   Dim userName = objODBCDataReader.Item("user_name").ToString() 'here it throws error as Arithmetic operation resulted in an overflow
End If

GetDataReader is a method that that will accept the query as string and return the result as Datareader.

let me know why this error is occurring while assigning a string value to a string variable?

am using

VisualStudio 2012
mysql 5.0
odbc driver 3.51
64 bit os
2

There are 2 answers

1
Zeddy On

In your IF statement you are TESTING to see if ROWS exist,

At this point you have not READ any data?

queryCommand= "select user_name,user_lastname,user_address from usertable"
objODBCDataReader = dbconObject.GetDataReader(queryCommand)
If objODBCDataReader.HasRows = True Then
  objODBCDataReader.Read()
  lsfinyear = objODBCDataReader.Item("user_name") 'here it throws error as Arithmetic operation resulted in an overflow
End If
0
sujith karivelil On

I have few suggestions for you:

1 Make us eof using command which will automatically dispose the connection at the end of using, you need not to bother about the connection issues even in case of any exception.

2 Use .Read method to read a row, and then only you can access values from the corresponding columns using its column index or by the column name.

3 You can use while instead for checking hasRow and then read.

Now consider the following code:

Dim queryString As String = "select user_name,user_lastname,user_address from usertable"
Using connection As New OdbcConnection(connectionString)
    Dim command As New OdbcCommand(queryString, connection)
    connection.Open()
    Dim reader As OdbcDataReader = command.ExecuteReader()
    While reader.Read()
        Console.WriteLine("user name={0}", reader(0).ToString)
        Console.WriteLine("user lastname{0}", reader("user_lastname").ToString)
    End While      
    reader.Close()
End Using

You will get more more details and examples from here