如何在传递给数据库之前从gridview获取xml [英] How to get an xml from the gridview before passing to database
问题描述
- 场景
我在gridview上显示,我有一个插入按钮。
当我点击插入按钮时,我应该在xml中获得griddata。同样必须传递到数据库。
我尝试了搜索,但没有得到适当的答案。
gridview详情
--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
必须使用存储过程在数据库表中传递。我想使用存储过程并使用xml来实现它。
xml在某种意义上:xml格式的gridview详细信息,并在存储过程中获取并插入表中。 。
请帮助我。
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.
推荐答案
您可以使用以下代码序列化对象
You can serialize the object using the following code
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;
}
这篇关于如何在传递给数据库之前从gridview获取xml的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!