I have written the following code to insert a text file and get data from My-Sql but i am not getting the required output.
I created my table as follows
ID int AutoIncrement
Fname varchar
FData LongBlob
My code
Collapse string filePath = Server.MapPath("AchTemplates/genACH.txt");
string filename = Path.GetFileName(filePath);
FileStream fs = new FileStream(filePath, FileMode.Open, FileAccess.Read);
BinaryReader br = new BinaryReader(fs);
Byte[] bytes = br.ReadBytes((Int32)fs.Length);
br.Close();
fs.Close();
string strQuery = "insert into tblFiles(FName,FData) values (@_FName, @_FData)";
MySqlCommand cmd = new MySqlCommand(strQuery);
cmd.Parameters.Add("@_FName", MySqlDbType.VarChar).Value = filename;
cmd.Parameters.Add("@_FData", MySqlDbType.LongBlob).Value = bytes;
InsertUpdateData(cmd);
private void download(DataTable dt)
{
Byte[] bytes = (Byte[])dt.Rows[0]["FData"];
Response.Buffer = true;
Response.Charset = "";
Response.Cache.SetCacheability(HttpCacheability.NoCache);
Response.AddHeader("content-disposition", "attachment;filename=" + dt.Rows[0]["FName"].ToString());
Response.BinaryWrite(bytes);
Response.Flush();
Response.End();
}
So can any one tell what's wrong going