Click here to Skip to main content
15,888,271 members
Home / Discussions / Database
   

Database

 
AnswerRe: SET NOCOUNT Pin
jschell24-Jul-12 7:16
jschell24-Jul-12 7:16 
QuestionSET NOCOUNT Pin
Member 348763223-Jul-12 22:15
Member 348763223-Jul-12 22:15 
AnswerRe: SET NOCOUNT Pin
Wayne Gaylard23-Jul-12 23:06
professionalWayne Gaylard23-Jul-12 23:06 
GeneralRe: SET NOCOUNT Pin
Member 348763223-Jul-12 23:09
Member 348763223-Jul-12 23:09 
GeneralIncreasing the session existing time in sql server Pin
yousefshokati20-Jul-12 22:29
yousefshokati20-Jul-12 22:29 
AnswerRe: Increasing the session existing time in sql server Pin
Eddy Vluggen21-Jul-12 7:57
professionalEddy Vluggen21-Jul-12 7:57 
GeneralRe: Increasing the session existing time in sql server Pin
jschell21-Jul-12 11:46
jschell21-Jul-12 11:46 
QuestionProblem saving file to MySQL Pin
Jassim Rahma20-Jul-12 21:27
Jassim Rahma20-Jul-12 21:27 
I am using this code to save file to MySQL but when I try to open the file after saving it I get an error saying:

Word was unable to read this document. It may be corrupt.

here is the code to write:

C#
file_name = Path.GetFileName(uploadResume.PostedFile.FileName);
file_extension = Path.GetExtension(uploadResume.PostedFile.FileName);

switch (file_extension)
{
case ".pdf": document_type = "application/pdf"; break;
case ".doc": document_type = "application/vnd.ms-word"; break;
case ".docx": document_type = "application/vnd.ms-word"; break;
case ".gif": document_type = "image/gif"; break;
case ".png": document_type = "image/png"; break;
case ".jpg": document_type = "image/jpg"; break;
case ".jpeg": document_type = "image/jpg"; break;
}

// calculate size of file;
int file_size = uploadResume.PostedFile.ContentLength;

// create array to read the file into it;
byte[] document_binary = new byte[file_size];
uploadResume.PostedFile.InputStream.Read(document_binary, 0, file_size);



and then passing it as parameters:

C#
sql_command.Parameters.AddWithValue("param_resume_format", document_type).MySqlDbType = MySqlDbType.VarChar;
sql_command.Parameters.Add("param_resume_data", MySqlDbType.Blob, file_size).Value = document_binary;



and here is how I am retrieving it:

C#
sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
sql_connection.Open();
sql_command = new MySqlCommand("sp_get_resume_by_id", sql_connection);
sql_command.CommandType = CommandType.StoredProcedure;
sql_command.Parameters.Add("param_resume_id", MySqlDbType.Int32).Value = resume_id;
sql_reader = sql_command.ExecuteReader();
sql_reader.Read();

if (sql_reader.HasRows)
{
file_name = sql_reader["resume_id"].ToString() + sql_reader["resume_ext"].ToString();
byte[] document_binary = (byte[])sql_reader["resume_data"];

FileStream file_stream = new FileStream(@"C:\Temp\" + file_name, FileMode.Create);
file_stream.Write(document_binary, 0, document_binary.Length);
file_stream.Close();
file_stream.Dispose();

txtResume.Visible = true;
}

AnswerRe: Problem saving file to MySQL Pin
Eddy Vluggen20-Jul-12 23:22
professionalEddy Vluggen20-Jul-12 23:22 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma21-Jul-12 2:33
Jassim Rahma21-Jul-12 2:33 
GeneralRe: Problem saving file to MySQL Pin
Eddy Vluggen21-Jul-12 7:54
professionalEddy Vluggen21-Jul-12 7:54 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma21-Jul-12 8:40
Jassim Rahma21-Jul-12 8:40 
GeneralRe: Problem saving file to MySQL Pin
Eddy Vluggen21-Jul-12 9:21
professionalEddy Vluggen21-Jul-12 9:21 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma21-Jul-12 9:42
Jassim Rahma21-Jul-12 9:42 
GeneralRe: Problem saving file to MySQL Pin
jschell21-Jul-12 11:48
jschell21-Jul-12 11:48 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma21-Jul-12 11:57
Jassim Rahma21-Jul-12 11:57 
GeneralRe: Problem saving file to MySQL Pin
jschell22-Jul-12 6:56
jschell22-Jul-12 6:56 
AnswerRe: Problem saving file to MySQL Pin
Eddy Vluggen21-Jul-12 12:58
professionalEddy Vluggen21-Jul-12 12:58 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma22-Jul-12 8:39
Jassim Rahma22-Jul-12 8:39 
GeneralRe: Problem saving file to MySQL Pin
Eddy Vluggen22-Jul-12 10:24
professionalEddy Vluggen22-Jul-12 10:24 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma22-Jul-12 10:29
Jassim Rahma22-Jul-12 10:29 
GeneralRe: Problem saving file to MySQL Pin
Eddy Vluggen22-Jul-12 10:42
professionalEddy Vluggen22-Jul-12 10:42 
GeneralRe: Problem saving file to MySQL Pin
Luc Pattyn22-Jul-12 10:43
sitebuilderLuc Pattyn22-Jul-12 10:43 
GeneralRe: Problem saving file to MySQL Pin
Jassim Rahma22-Jul-12 11:50
Jassim Rahma22-Jul-12 11:50 
AnswerRe: Problem saving file to MySQL Pin
Luc Pattyn22-Jul-12 11:57
sitebuilderLuc Pattyn22-Jul-12 11:57 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.