fantasylan
asked on
How to serialize data in SQLDataReader into XML
Hi
I have a function like the one below
public void somefunction(int parameter)
{
//SqlConnection defined and working.
SqlCommand cmd = new SqlCommand("SELECT * FROM TABLE WHERE ID = parameter",SQLConnection);
SqlDataReader reader = cmd.ExecuteReader();
}
How do I convert the data in the SqlDataReader into XML so it can be used for a web method in a web-service. I probably think XML Serialization is the way to go out here but I have no clue how to serialize the SqlDataReader.
Thanks
I have a function like the one below
public void somefunction(int parameter)
{
//SqlConnection defined and working.
SqlCommand cmd = new SqlCommand("SELECT * FROM TABLE WHERE ID = parameter",SQLConnection);
SqlDataReader reader = cmd.ExecuteReader();
}
How do I convert the data in the SqlDataReader into XML so it can be used for a web method in a web-service. I probably think XML Serialization is the way to go out here but I have no clue how to serialize the SqlDataReader.
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
http://msdn.microsoft.com/en-us/library/system.data.datatable.writexml.aspx
Attached is an example in VB.Net (but heys... the concepts are the same for C#), where "ds" is a DataSet with multiple DataTables.
Open in new window