Click here to Skip to main content
15,883,901 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
Hi,
I am developing a c# desktop app which is a CRM using vs 2008 and Sql server 2005. There is an option to upload any file may it be in any format, specially docs,excel,jpg,pdf etc in a particular customers record , I am able to upload the files in the table where i store the file content a binary data,but i'm not able to retrive the files. Is there any solution or any other method.
Posted
Updated 2-May-13 20:17pm
v2
Comments
Sergey Alexandrovich Kryukov 3-May-13 1:50am    
Use ADO.NET. Did you do any research in the documentation, before asking this question? If not, do it first.
—SA
Praveen_P 3-May-13 2:19am    
Hi,
I updated my question, thank you for your consideration
[no name] 3-May-13 7:13am    
"i'm not able to retrive the files", means nothing to anyone but you. Why are you not able to get the files? Can you not write a SELECT query? Did you do any research at all? This question has been asked and answered here 5 times a week for a very long time. A simple google search will get you millions of results. What have you tried? Where is the code that you have written that demonstrates your problem? What problem? What errors do you get?
Scott A Parker 3-May-13 17:42pm    
Here is some code from a personal project. I use MySql but the procedures should be fairly consistent across most SQL database systems or should be easy to modify.

<pre lang="c#">//********************************************************************************
//Convert image for storage in database
//********************************************************************************

MemoryStream stream = new MemoryStream();
picID.Image.Save(stream, System.Drawing.Imaging.ImageFormat.Jpeg);
byte[] pic_data = stream.ToArray();


string q = "Update customer Set Customer_FirstN='" + FName + "', Customer_MiddleN='" + MName + "', Customer_LastN='" + LName +
"', Customer_Add1='" + Add1 + "', Customer_Add2='" + Add2 + "', Customer_City='" + City + "', Customer_State='" + State +
"', Customer_Zip='" + Zip + "', Customer_Phone='" + Phone + "', Customer_Cell='" + Cell + "', Customer_Sex='" + Sex +
"', Customer_Race='" + Race + "', Customer_Height='" + Height + "', Customer_Weight='" + Weight + "', Customer_Eyes='" + Eyes +
"', Customer_Hair='" + Hair + "', Customer_Flag='" + Flag + "', Customer_Notes='" + Note + "', Customer_ID_Num='" + IdNum +
"', Customer_ID_Issue_State='" + IdState + "', Customer_ID_Type='" + IdType + "', Customer_BDate='" + DOB + "', Customer_ID_Exp='" + IdExp +
"', Customer_ID_Issue='" + IdIssue + "', Customer_Class='" + Class + "', Customer_Image=@Pic Where Customer_ID_Num='" + txtIDNum.Text + "'";


string Param = "@Pic";

public void dbWrite(string Query, string Param, Array pic_data )
{

MySqlConnection con = new MySqlConnection(conStr);
MySqlCommand cmd = new MySqlCommand(Query, con);
if (Param != null)
{
cmd.Parameters.AddWithValue(Param, pic_data);
}

con.Open();
cmd.ExecuteNonQuery();
}

//Reading image from database
//*************************************************************************
public MemoryStream dbReadImage(string Query, string Image)
{
MemoryStream stream;

MySqlConnection con = new MySqlConnection(conStr);
MySqlCommand cmd = new MySqlCommand(Query, con);

MySqlDataAdapter dp = new MySqlDataAdapter(cmd);
DataSet ds = new DataSet("MyImages");

byte[] MyData = new byte[0];

dp.Fill(ds, "MyImages");
DataRow myRow;
myRow = ds.Tables["MyImages"].Rows[0];

MyData = (byte[])myRow[Image];

return stream = new MemoryStream(MyData);

}</pre>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900