Hi all,
I am using OleDbConnection for connecting with MySQL.Using INSERT query for inserting images to MySQL db with C# code.
The code is given below :
string strConn="PROVIDER=MySQLProv;SERVER=192.168.1.8;DB= test;UID=test;PWD=;PORT=;";
OleDbConnection objConn;
objConn=new OleDbConnection (strConn);
objConn.Open();
Image image1=pictureBox.Image;
image1.Save ( textBox1.Text ,ImageFormat.Bmp );
System.IO .FileStream stream =new FileStream ("d://shri.bmp" ,System.IO.FileMode .Open ,System.IO.FileAccess .Read );
System.Int32 flength=0;
flength=(int)stream.Length;
System.Byte[] buffer=new Byte[flength ];
string imagename=textBox1.Text+count ;
string strname="shri";
string sql="INSERT INTO tblcustomer VALUES(?,?,?)";
OleDbCommand cmd = new OleDbCommand(sql,objConn);
cmd.Parameters .Add (new OleDbParameter ("@varName",strname));
cmd.Parameters .Add (new OleDbParameter ("@varImage",imagename));
cmd.Parameters .Add (new OleDbParameter ("@image",OleDbType.Binary ).Value =buffer);
cmd.ExecuteNonQuery();
objConn.Close ();
The Error is:
An unhandled exception of type 'System.InvalidCastException' occurred in system.data.dll
Additional information: The OleDbParameterCollection only accepts non-null OleDbParameter type objects, not Byte[] objects.
Waiting for Reply
-Shri
************************************************** ********************
Sent via Fuzzy Software @ http://www.fuzzysoftware.com/
Comprehensive, categorised, searchable collection of links to ASP & ASP.NET resources...