Can anyone save image to MySQL from Pocket PC?

Can anyone save image to MySQL from Pocket PC?

Postby john_elden2002 » Thu 07 Apr 2005 17:23

I want to save images (bmp, jpg, tif...) to MySql database using my Pocket PC. I am using MySQLDirect.net 2.70.40 trial version. Below is my code. Can anyone help me?
Code: Select all
      OpenFileDialog fdlg = new OpenFileDialog();
      fdlg.InitialDirectory = @"" ;
      fdlg.Filter = "Jpeg files (*.jpg)|*.jpg|MS bitmap Files (*.bmp)|*.bmp" ;
      fdlg.FilterIndex = 2 ;

      if(fdlg.ShowDialog() == DialogResult.OK)
      {
         FileStream fs = new FileStream(fdlg.FileName, FileMode.Open, FileAccess.Read);
         byte[] buffer = new byte[fs.Length];   
         fs.Read(buffer, 0, (int)fs.Length);
          fs.Close();
         // Method 1
         dataSet = new System.Data.DataSet("Image");
         string strSql = "select * from file";
         MessageBox.Show(connection.ConnectionString);
         mySqlConnection = new MySqlConnection(connection.ConnectionString);
         mySqlConnection.Open();
         mySqlDataAdapter = new MySqlDataAdapter(strSql, mySqlConnection);
         mySqlCommandBuilder = new MySqlCommandBuilder(mySqlDataAdapter);
         mySqlDataAdapter.Fill(dataSet,"Table");   
   
         dataRow = dataSet.Tables["Table"].NewRow();
         dataRow["id"] = 1;
         dataRow["extension"] = fdlg.FileName;
         dataRow["data"] = buffer;
         dataSet.Tables["Table"].Rows.Add(dataRow);   
         // trying to update the table to add the image
try
{
         mySqlDataAdapter.Update(dataSet,"Table");      
}
         catch (System.NullReferenceException msg)
         {
            MessageBox.Show(msg.Message, "SQL error");
         }
         finally
         {
            mySqlConnection.Close();
         }         
         // End method 1

         // Method 2
         /*MySqlConnection mySqlConnection = new MySqlConnection(connection.ConnectionString);
         MySqlBlob myBlob = new MySqlBlob(buffer);
         MySqlCommand myCommand = new MySqlCommand("Insert into file (id, extension, data) values(1, 'something', :MyData);", mySqlConnection);
         //MySqlCommand myCommand = new MySqlCommand("Insert into file set id=1, extension='something';", mySqlConnection);
         myCommand.Parameters.Add("MyData", myBlob);
         mySqlConnection.Open();
         try
         {   
            myCommand.ExecuteNonQuery();
         }
         catch (System.NullReferenceException msg)
         {
            MessageBox.Show(msg.Message, "SQL error");
         }
         finally
         {
            mySqlConnection.Close();
         }*/
         // End method 2
      }
Method 1 works on PC, but throw NullReferenceException when running it from Pocket PC. Method 2 works without save the image to database from my Pocket PC. I copy method 2 from someone on the forum, but I could not get it working.

Thanks

John
john_elden2002
 
Posts: 3
Joined: Fri 25 Mar 2005 21:19

Postby Serious » Mon 11 Apr 2005 09:35

We have fixed this problem (NullReferenceException) for the MySQLDirect .NET Mobile.
Look forward for the next build.

New build will be released in a few days.
Serious
 

Postby john_elden2002 » Tue 19 Apr 2005 23:06

When will the new build release?
john_elden2002
 
Posts: 3
Joined: Fri 25 Mar 2005 21:19

Postby Serious » Wed 20 Apr 2005 07:08

The new release will be issued in few hours
Serious
 

Postby john_elden2002 » Thu 21 Apr 2005 21:52

Thanks. The new release works to save image to MySQL.

How do I read the image from MySQL and save it to a file? Thanks.
john_elden2002
 
Posts: 3
Joined: Fri 25 Mar 2005 21:19

Postby Serious » Fri 22 Apr 2005 11:05

There is a "Pictures" demo project in MySQLDirect .NET Mobile installation folder.
It demonstrates using MySQLDirect .NET Mobile for working with graphics. The sample demonstrates retrieving binary data from MySQL database and displaying it at the monitor, loading and saving pictures into the file and database.
Serious
 


Return to dotConnect for MySQL