Click here to Skip to main content
15,938,446 members
Please Sign up or sign in to vote.
2.00/5 (4 votes)
See more:
how to cast object of type 'System.Byte[]' to type 'System.IConvertible'. in c# winapp(window Application)
Posted
Comments
Zoltán Zörgő 2-Oct-12 5:06am    
What exactly do you want to achieve? IConvertible is for scalars. Byte array is an array. It is working not like that. You will probably need to rethink.
Shubh Agrahari 2-Oct-12 6:16am    
i want to retrive image from mysql db(a colume name image datatype longblob) onto my winapp form in the form of int.....

1 solution

how to cast object of type 'System.Byte[]' to type 'System.IConvertible'
You cannot cast one of this into other or vice-versa. They are totally different objects and is not possible - One is Byte array structure and other is an Interface.
 
Share this answer
 
Comments
Shubh Agrahari 2-Oct-12 6:11am    
then finally what to do...beside this query have any other option to convert longblob into int in c#???
Sandeep Mewara 2-Oct-12 6:59am    
Why would you have a longblob datatype to keep int values? I am not sure of your feature but sounds a little weird implementation.
Shubh Agrahari 2-Oct-12 7:22am    
1st i am retriving file from opendialouge box and saving in into mysql database.....using this code.....

private string curFileName = null;
OpenFileDialog openDlg = new OpenFileDialog();

openDlg.Filter = "JPeg Image|*.jpg|Bitmap Image|*.bmp|Gif Image|*.gif";

string filter = openDlg.Filter;

openDlg.Title = "Open only Image Files";

if (openDlg.ShowDialog() == DialogResult.OK)
{

curFileName = openDlg.FileName;

textBox2.Text = curFileName;
}
FileStream fs = new FileStream(curFileName,

FileMode.OpenOrCreate, FileAccess.Read);
int file = (int)fs.Length;
byte[] rawData = new byte[file];

fs.Read(rawData, 0, (int)file);

fs.Close();
string str = "select * from Doc";
if (con.State != ConnectionState.Open)
con.Open();
MySqlDataAdapter da = new MySqlDataAdapter(str,con);
MySqlCommandBuilder mcb = new MySqlCommandBuilder(da);
DataSet ds = new DataSet("Doc");
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
da.Fill(ds,"Doc");
DataRow row=ds.Tables["Doc"].NewRow();
row["pfno"] = label7.Text;
row["depname"] = label8.Text;
row["docname"] = comboBox1.Text;
row["docdisc"] = textBox1.Text;
row["addedby"] = sd.uname;
row["depdoc"] =rawData;
ds.Tables["Doc"].Rows.Add(row);
da.Update(ds,"Doc");
if(con!=null)
{
if(con.State==ConnectionState.Open)
{
con.Close();
con.Dispose();
}
MessageBox.Show("Document Saved Successfully");
}
_____________________________________________________________________________________
it is running succesfully for saving but now the main fault when i am retriving that ID specific image on winform using this code....

try
{
string str1 = "select * from doc where pfno='" + label7.Text + "' and depname='"+label8.Text+"'";
con.Open();
MySqlCommand cmd = new MySqlCommand(str1, con);
MySqlDataReader data = cmd.ExecuteReader();
if (data.Read())
{
string name = data.GetString(data.GetOrdinal("depname"));
" error Ocurring on this line below and error is Invalid Cast Exception(Object must implement IConvertible.)"
int filesize = data.GetInt32(data.GetOrdinal("depdoc"));
byte[] rawData = new byte[filesize];
data.GetBytes(data.GetOrdinal("depdoc"), 0, rawData, 0, filesize);
FileStream fs = new FileStream(name, FileMode.Create, FileAccess.Write);
fs.Write(rawData, 0, filesize);
fs.Close();
pictureBox1.Image = new Bitmap(name);
}

}
catch(Exception ex)
{
MessageBox.Show("Document Test " + ex);
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
con.Dispose();

}
so sir now any help???

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900