Hello,
I've got very odd problem.
I use windows application to store files in data base (MySql) and then to extract this files from data base and save it on hdd. But when i save them back to hdd tihs files are 1Kb less from original file. When i insert pictures this 1kb obviously is not imported and the pictures is shown. But other files when try to be opened is corrupted or if they open some error message is shown.
So the code that i use to save file in DB is:
The code that extract files from database and save them to hdd is:
Can someone help me to find missing Kb :-)
Thanks!
I've got very odd problem.
I use windows application to store files in data base (MySql) and then to extract this files from data base and save it on hdd. But when i save them back to hdd tihs files are 1Kb less from original file. When i insert pictures this 1kb obviously is not imported and the pictures is shown. But other files when try to be opened is corrupted or if they open some error message is shown.
So the code that i use to save file in DB is:
Code:
MySqlConnection con = new MySqlConnection("SERVER=localhost;" +
"DATABASE=dbname;" +
"UID=user;" +
"PASSWORD=user;");
MySqlDataAdapter da = new MySqlDataAdapter("Select * From test", con);
MySqlCommandBuilder MyCB = new MySqlCommandBuilder(da);
DataSet ds = new DataSet("test");
da.MissingSchemaAction = MissingSchemaAction.AddWithKey;
FileStream fs = new FileStream(@"C:\image.rar", FileMode.OpenOrCreate, FileAccess.Read);
byte[] MyData = new byte[fs.Length];
fs.Read(MyData, 0, System.Convert.ToInt32(fs.Length));
fs.Close();
da.Fill(ds, "test");
DataRow myRow;
myRow = ds.Tables["test"].NewRow();
myRow["id"] = "12";
myRow["blobdata"] = MyData;
ds.Tables["test"].Rows.Add(myRow);
da.Update(ds, "test");
con.Close();
Code:
MySqlConnection con = new MySqlConnection("SERVER=localhost;" +
"DATABASE=dbname;" +
"UID=user;" +
"PASSWORD=user;");
MySqlDataAdapter da = new MySqlDataAdapter("Select * From test where id = 12", con);
MySqlCommandBuilder MyCB = new MySqlCommandBuilder(da);
DataSet ds = new DataSet("test");
byte[] MyData = new byte[0];
da.Fill(ds, "test");
DataRow myRow;
myRow = ds.Tables["test"].Rows[0];
MyData = (byte[])myRow["blobdata"];
int ArraySize = new int();
ArraySize = MyData.GetUpperBound(0);
FileStream fs = new FileStream(@"C:\Data\image.rar", FileMode.OpenOrCreate, FileAccess.Write);
fs.Write(MyData, 0, ArraySize);
fs.Close();
Thanks!
Comment