Click here to Skip to main content
15,904,348 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
--scenario

I have on gridview displayed and i have an insert button.

When i click on insert button, i should get the griddata in xml. And the same has to be passed to the database.

I tried searcing but didnot get the appropriate answer.

gridview details

userid     startdate           enddate
1        12/22/2013 13:30     12/22/2013 23:30
2        12/22/2013 13:30     12/22/2013 23:30
3        12/22/2013 13:30     12/22/2013 23:30


the same has to be passed in database table using stored procedure. I want to do it using stored procedure and also using xml.

xml in the sense : gridview details in xml format and fetch in stored procedure and insert in the table..

Kindly help me.
Posted
Comments
Kriti Jain 10-Dec-13 4:42am    
You have to first store the values of the grid in an object and after that you can covert that object into XML stream and pass it to the database.
anurag19289 10-Dec-13 13:22pm    
i will try that and get back to you

1 solution

You can serialize the object using the following code

C#
public static string  Serialize<t>(object obj)  // Serializing the object to XML string
        {
            StringBuilder sb = new StringBuilder();
            using (TextWriter writer = new StringWriter(sb))
            {
                XmlWriterSettings settings = new XmlWriterSettings();
                settings.OmitXmlDeclaration = true;

                var serializer = new XmlSerializer(typeof(T));
                serializer.Serialize(XmlWriter.Create(writer, settings), obj);
            }
            string form = sb.ToString();
            return form;
        }
 
Share this answer
 
v2

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