C# .NET - Arithmetic operation resulted in an overflow.

Asked By ajmal yazdani on 20-Feb-07 06:05 AM

I have a table "File" with two fields...

ID - int

Logo - Blob

there is one Blob data (logo) corresponds to the ID.

now, am want to retrieve that logo to picturebox, for that i m using below code....

try

{

MySqlConnection cn = new MySqlConnection(ConfigurationSettings.AppSettings["connectionString"]);

MySqlCommand cmd = new MySqlCommand("SELECT ID, Logo FROM FILE order by ID", cn);

MySqlDataAdapter da = new MySqlDataAdapter(cmd);

DataSet ds = new DataSet();

da.Fill(ds, "BLOBTest"); //Error Occured

int c = ds.Tables["BLOBTest"].Rows.Count;

if (c > 0)

{

Byte[] byteBLOBData = new Byte[0];

byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["Logo"]);

MemoryStream stmBLOBData = new MemoryStream(byteBLOBData);

pictureBox1.Image = Image.FromStream(stmBLOBData);

}

cn.Close();

}

catch (Exception ex)

{ MessageBox.Show(ex.Message); }

why dataset can't fill and throws the error....Arithmetic operation resulted in an overflow.

Ajmal

try this

Robert Stanton replied to ajmal yazdani on 20-Feb-07 08:58 AM

I wouldn't use this as a solution, but I am interested in seeing what results it gives

unchecked {
da.Fill(ds,
"BLOBTest"); //Error Occured
}

Try that code and let us know how your application behaves

Also, as a side note, there is no need to set byteBLOBData = new Byte[0]; You can either do
Byte[] byteBLOBData;
byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["Logo"]);

Or
Byte[] byteBLOBData = (Byte[])(ds.Tables["BLOBTest"].Rows[c - 1]["Logo"]);

no, its gives the same result and same line, but see....inside

ajmal yazdani replied to Robert Stanton on 20-Feb-07 11:26 PM

the above u suggested is not work. again the same error at the same line.

but, the above line of code is successfully run with SqlServer database, it occur problem with only MYSQL server.

in case of "sql server" datatype for logo is "image" and image saved in database in "Binary" format, ok

but, in case of "MySql" datatype for logo is "blob" and image saved in database in "Blob" format as I see....

i think the problem is of datatype and we have to do other way before retrive blob into dataset.

can u suggest more, still i have a problem.

thnx

Ajmal

What are the values for ID

Robert Stanton replied to ajmal yazdani on 21-Feb-07 07:00 AM
What is the type and values for the id column in that table?
type "int"
ajmal yazdani replied to Robert Stanton on 21-Feb-07 10:54 PM

SELECT ID, Logo FROM FILE order by ID

currently there is 1 record in table

so, value of ID=1