954,593 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

How To Convert SQL Stored Procedure to XML/XLST with C#

Hello,

I am getting the contents on my website from database using SQL Stored Procedure (C#).

Now, I want to change the output look with XML / XSLT. How can I do this?

Something like this http://forums.asp.net/t/1230093.aspx/1 but am not sure how to go about it, am new to C# .NET

My sample code.

SqlConnection objConn = new SqlConnection();
objConn.ConnectionString = "server=172.16.8.444\\SQL2005;database=********;Integrated Security=false;user=********;pwd=*********;";
objConn.Open();
SqlCommand objCmd = new SqlCommand("getContent", objConn);
objCmd.CommandType = CommandType.StoredProcedure;

SqlDataAdapter result = new SqlDataAdapter(objCmd);

DataSet selectResults = new DataSet();
result.Fill(selectResults); // get dataset

objCmd.ExecuteReader();

foreach (DataRow row in selectResults.Tables[0].Rows)
{
Literal1.Text = (selectResults.Tables[0].Rows[0]["title"].ToString() + "
" + selectResults.Tables[0].Rows[0]["created_at"].ToString() + "
" + selectResults.Tables[0].Rows[0]["summary"].ToString() + "
" + selectResults.Tables[0].Rows[1]["title"].ToString() + "
" + selectResults.Tables[0].Rows[1]["created_at"].ToString() + "
" + selectResults.Tables[0].Rows[1]["summary"].ToString() + "
" + selectResults.Tables[0].Rows[2]["title"].ToString() + "
" + selectResults.Tables[0].Rows[2]["created_at"].ToString() + "
" + selectResults.Tables[0].Rows[2]["summary"].ToString());

}

Charles.m
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

If you want to alter the way the results look on the page you can always include HTML in your literal control and apply CSS classes. Much easier than XSLT.
Or do you want to change the database output to XML?

hericles
Practically a Posting Shark
823 posts since Nov 2007
Reputation Points: 136
Solved Threads: 168
 

Thank you very much hericles.

I don't necessarily have to output it as XML but I think it will be the only way to add somethings I need like making my content READ MORE, I just want to alter the way the result look.

EXAMPLE

What I have currently:

Test Item 1 12/5/2011 8:02:07 PM Test Item 1 Summary Test Item 2 12/5/2011 8:48:36 PM Test Item 2 Summary Test Item 3 12/5/2011 8:49:57 PM Test Item 3 Summary

What I need:

Article 1 5 December, 2011 Summary text Read More >> (here will take me to the full description)


How can I go about it?

Charles.m
Newbie Poster
3 posts since Dec 2011
Reputation Points: 10
Solved Threads: 0
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: