473,395 Members | 1,692 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Binary serialization on MySQL

How can i binary serialize objects on MySQL

also can you provide a step by step approach of running the program below and which software and platform do i need to get the program working;

Expand|Select|Wrap|Line Numbers
  1. using MySql.Data.MySqlClient;
  2.  
  3. private string imagePath = string.Empty;
  4. private string MySqlConnString =
  5.   "Server = localhost; Uid = root; Pwd = password;
  6. Database = demo;";
  7. private void SerializeNSaveToDB()
  8. {
  9.   MemoryStream str = new MemoryStream();
  10.   try
  11.   {
  12.     string column = "?IMAGE ";
  13.     Image img = Image.FromFile(imagePath);
  14.     BinaryFormatter oBFormatter = new BinaryFormatter();
  15.     oBFormatter.Serialize(str, img);
  16.     byte[]oSerializedImg = str.ToArray();
  17.     string Query = "INSERT INTO DEMO (NAME, PHOTO) VALUES('Image 1',  ? IMAGE)
  18.       ";Call_Upload_Object(Query, oSerializedImg, column);
  19.   }
  20.   catch (Exception ex)
  21.   {
  22.     MessageBox.Show(ex.Message);
  23.   }
  24.   finally
  25.   {
  26.     str.Close();
  27.   }
  28. }
  29.  
  30. private void Call_Upload_Object(string query, byte[]image, string column)
  31. {
  32.   MySqlConnection oMySqlConnection = new MySqlConnection(MySqlConnString);
  33.   try
  34.   {
  35.     MySqlCommand oMySqlCommand = new MySqlCommand();
  36.     oMySqlConnection.Open();
  37.     oMySqlCommand.Connection = oMySqlConnection;
  38.     oMySqlCommand.CommandText = query;
  39.     oMySqlCommand.Parameters.Add(column, image);
  40.     oMySqlCommand.ExecuteNonQuery();
  41.   }
  42.   catch (Exception ex)
  43.   {
  44.     throw ex;
  45.   }
  46.   finally
  47.   {
  48.     oMySqlConnection.Close();
  49.   }
  50. }
Jul 17 '09 #1
5 3223
Dormilich
8,658 Expert Mod 8TB
what language is that, C#?

note that technical question usually belong in the answers section of the appropriate forum.
Jul 17 '09 #2
i don't really know, what programming language it is, thats one of the help i need from this forum
Jul 19 '09 #3
Dormilich
8,658 Expert Mod 8TB
I'll move it to the C# forum for now, maybe the people there know better.
Jul 19 '09 #4
GaryTexmo
1,501 Expert 1GB
I'm not sure I understand the question... are you asking how to do it, or how to understand/work the code snippet you posted?

I can say the snippet is definitely C#, and if you need a good, free, environment to get it working in, try a google search for "Microsoft Visual C# Express Edition".
Jul 19 '09 #5
thanks for your reponse.

Can I get a code/program writing in C++ or JAVA that implements BINARY SERIALIZATION on MYSQL.
Jul 20 '09 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: hs | last post by:
Hi I am serializing a dataset using a binary formatter as follows: IFormatter formater = new BinaryFormatter(); formatter.Serialize(stream, ds); // ds=DataSet, stream=MemoryStream .... DataSet...
9
by: Ching-Lung | last post by:
Hi all, I try to create a tool to check the delta (diff) of 2 binaries and create the delta binary. I use binary formatter (serialization) to create the delta binary. It works fine but the...
2
by: Dave Veeneman | last post by:
I'm working on a project where I have to persist data to a file, rather than to a database. Basically, I need to save the state of several classes, each of which will have a couple of dozen...
11
by: ajou_king | last post by:
I was running some tests on my Win32 1GHZ processor to see how long it would take to transmit objects numerous times via TCP/IP using C# ..NET Remoting vs the C++ trustworthy method of binary...
7
by: schoenfeld1 | last post by:
I've implemented IPC between two applications using named pipes and binary serialization, but have noticed that the binary formatter is rather slow. It seems that the binary formatter reflects...
15
by: Jacques | last post by:
Hi I am an dotNet newby, so pardon my ignorance. I am looking for a method of saving/copying a managed class to a stream/file WITHOUT saving the object's state, eg. if I have a ref class with...
0
by: Vince Filby | last post by:
Hi, We are working with distributing Lucene.net. We have Master Index Server which takes responsibility of distributing the index searching to multiple Index Servers by calling the remote...
1
by: kikisan | last post by:
I am developing a windows service which utilizes the following classes: interface IPersistable; abstract class PersistableObject : IPersistable;
2
by: mkvenkit.vc | last post by:
Hello, I hope this is the right place to post a question on Boost. If not, please let me know where I can post this message and I will do so. I am having a strange problem with std::string as...
1
by: sandeepbhutani304 | last post by:
have 2 projects communicating each other with .NET remoting. But when I am trying to call these functions I am getting the error: The input stream is not a valid binary format. The starting...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.