473,434 Members | 1,854 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,434 software developers and data experts.

Blob in MySql using c#

Hi I want to storage a txt file into mysql using a blob and after that extract it, the code i use to save it is:
Expand|Select|Wrap|Line Numbers
  1.  
  2.             fs = new FileStream("C:\\Documents and Settings\\Pru.txt", FileMode.Open, FileAccess.Read);
  3.             FileSize = fs.Length;
  4.             rawData = new byte[FileSize];
  5.             fs.Read(rawData, 0, Convert.ToInt32(FileSize));
  6.             fs.Close();
  7.             SQL = "INSERT INTO EEG (eeg)values ('" + rawData + "' )";
  8.             cmd.CommandText = SQL;
  9.             cmd.ExecuteNonQuery();
  10.  
and my code to extract it is:

Expand|Select|Wrap|Line Numbers
  1.     MySqlDataReader myData;
  2.     string SQL ="SELECT EEG FROM EEG WHERE id_eeg = '" + id + "' ";
  3.     cmd.CommandText = SQL;
  4.     myData = cmd.ExecuteReader();
  5.     myData.Read();
  6.     rawData = new byte[1000];
  7.     myData.GetBytes(0, 0, rawData, 0,1000);
  8.     for (i = 0; i < rawData.Length;i++)
  9.         final[i] = Convert.ToString((rawData[i] << 8) + rawData[i+1]);
  10.  fs = new FileStream("C:\\Documents and Settings\\Pru2.out", FileMode.OpenOrCreate,
  11. FileAccess.Write);
  12.     fs.Write(rawData, 0,1000); 
  13.     fs.Close();
  14.     myData.Close();
  15.     conn.Close();
  16.  
  17.  
but I get a file with a text like this:
System.Byte[]

And it is not the text of the original file
Help!!!!
Thx
Feb 7 '08 #1
3 18125
Help!!!!! please!!!!!!!!!!!
Feb 8 '08 #2
I think I can help you. I also had the same problem.

Instead of this:-

SQL = "INSERT INTO EEG (eeg)values ('" + rawData + "' )";
cmd.CommandText = SQL;
cmd.ExecuteNonQuery();
try:-

SQL = "INSERT INTO EEG VALUES(?File)";
cmd.CommandText = SQL ;
cmd.CommandType = CommandType.Text;
cmd.Parameters.Add("?File", rawData);
cmd.ExecuteNonQuery();

It worked for me!

Here is a link to where I got this information
http://dev.mysql.com/doc/refman/5.0/...sing-blob.html
Mar 10 '08 #3
Plater
7,872 Expert 4TB
Your read method confuses me. What are you doing with the >>8 and stuff?
Are you familiar with System.Text.Encoding.ASCII ?

And somewhere you are calling (possibly implicitly) a .ToString() on your byte[] object.
Mar 10 '08 #4

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

Similar topics

0
by: linus | last post by:
Anyone try insert image or binary files to MySQL using ASP.NET? Thanks a lot
1
by: Devendra | last post by:
How could i insert a pdf file in mysql using PHP and when i access from database it must be open in .html format plz give me reply
0
by: Ginoboy | last post by:
Hello there I have a problem in executing mysql using java netbeans. all i want is to execute a batch file. this is my code: "try { ...
1
by: mohammedsk | last post by:
Hi, I am trying to save information into MySQL using PHP. The data I am saving is in Arabic language. The database table will show some "???" or other characters. If I insert the text directly...
1
by: ariel gons | last post by:
This is one of my project and also my thesis in school. How can I get data on database MYSQL using javascript function? Is there anybody here can help me with this problem.. Can anyone give...
1
by: chirag thakor | last post by:
how i can import data from Excel to MySql using php.
9
paulrajj
by: paulrajj | last post by:
hi everybody, i am newbie to php and mysql. i have a little bit knowledge about php with xml. how to insert and select the records from xml to mysql using php?
3
by: emsik1001 | last post by:
Hi http://dev.mysql.com/doc/query-browser/en/mysql-query-browser-connection.html I'm trying to connect from my Windows based PC to a dedicated server which is running on Linux system. I...
4
by: apssiva | last post by:
Hi, i tiring to insert excel data into mysql using php. 1. i saved the Excel data as a CSV file. 2. i use below code to retrieve data. $fcontents = file('./ite_APS.csv');...
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
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,...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?

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.