Click here to Skip to main content
12,695,404 members (25,822 online)
Rate this:
Please Sign up or sign in to vote.
See more: C#
hi, my name is modeste
am having a problem concerning how to download a file from database using datalist view control on this is the code am having but it is not giving result
 SqlCommand cmd = new SqlCommand("select * FROM WordFiles where id=@id ", con);

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable dt = new DataTable();
                dt.TableName = "WordFiles";
                DataSet dS = new DataSet();
                dS.DataSetName = "WordFiles";
               // StringWriter sw = new StringWriter();
              //  dS.WriteXml(sw, XmlWriteMode.IgnoreSchema);
               // string s = sw.ToString();

                SqlDataReader drr = cmd.ExecuteReader();

                if (drr.Read())
                // string attachment = "attachment; filename=test.xml";
                Response.ContentType = drr["type"].ToString();
                Response.AddHeader("content-disposition", "attachment;filename=" + drr["name"].ToString());
Posted 14-Jun-13 1:07am
Updated 14-Jun-13 6:03am
ThePhantomUpvoter 14-Jun-13 6:18am
Debug your code. Define what "not giving result" means? Did you check your SQL? Why are you adding a parameter to your SQL when the parameter does not exist?
carpediemmodeste 14-Jun-13 7:38am
ThePhantomUpvoter can you plz help me: those are the information about my sql; i have a table called wordFiles with id as primary key(int), name(the name of the file which is in table), data(which is having the content of the file) and the type (wich is storing the exenstion),if you have the code of downloading a file using a button in a datalist view plz help me .Thank you so much!!
ThePhantomUpvoter 14-Jun-13 9:11am
Well I am not sure how to help you.
1. You have not debugged your code.
2. You have not specified what error message you are getting.
3. You specify a parameter named "@id" but try to assign a value to a parameter named "id".
4. You have not detailed what result you are getting with your code.
carpediemmodeste 14-Jun-13 10:32am
Thank you so much for your time you are giving to me for help i have degugged the code, then runned the code then when i click on the button i get nothing ! no error, nothing happen
may table in database is having 3 colomns which are : id(as primary key), data(where the file will be) and typ(which will hold the extension of any file uploaded in a table), then on the datalist i want that if a user click on button he/she can download that file. thank you!
richcb 14-Jun-13 11:04am
As ThePhantomUpvoter has stated, you have not provided enough information. But I can tell you your query will not return anything.

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

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170118.1 | Last Updated 14 Jun 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100