Click here to Skip to main content
15,894,180 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have a XML data type column in Database Table.

this way, I used to insert my XML file in to SQL server
C#
XmlReader XMLFile;

   XMLFile = XmlReader.Create(@"E:\coverindex1.xml", new XmlReaderSettings());
   cmd.Parameters.Add(new SqlParameter("@code_array", XMLFile));


Now I need to retrieve that column and save the data as XML File in local drive.
My C# code for retrieve :

C#
String sql1 = "SELECT Code_Array FROM SecretCodeTable_1 WHERE Secret_Key = @secretKey";

           SqlCommand cmd = new SqlCommand(sql1, con);

            cmd.Parameters.AddWithValue("@secretKey", int.Parse(textBox1.Text));

             using (SqlDataReader reader1 = cmd.ExecuteReader())
             {
                 if (reader1.Read())
                 {
                     xdoc.LoadXml(reader1["Code_Array"]);
                     xdoc.Save(@"E:\myfile.xml");

                     }



But I couldn't get output. Please any one correct me.!

Thank you!
Posted
Comments
CHill60 11-Dec-15 8:45am    
When you step through your code are you going into the body of the if-statement?
Does xdoc get populated?
John C Rayan 11-Dec-15 11:43am    
Few things you have to check here.

Firstly, make sure that you have inserted the XML successfully in to DB.
Secondly , check that the secretKey receives a valid value from textbox , and
thirdly as Chilli60 suggested you have to see if you are going to the if block to write the file.

Debug and find out. We do not have neither your env nor the code

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