i want to change the output from columns to rows using string builder in asp.net
My code as follows
System.Text.StringBuilder sbNews = new System.Text.StringBuilder();
string myConString = ConfigurationManager.ConnectionStrings["Reception2_DB"].ConnectionString;
using (SqlConnection conn = new SqlConnection(myConString))
{
string query;
query = Select Subject,Description,Link,Entereddate from LatestNewsMaster and active <>'d'";
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
sbNews.Append(rdr[3].ToString() + "
");
sbNews.Append(rdr[0].ToString() + "
");
sbNews.Append(rdr[1].ToString() + "
");
sbNews.Append(rdr[2].ToString() + "
");
}
}
NewsTicker = sbNews.ToString();
}
In database record as follows
Subject Description Link entereddate
Defects Defects page Defects.aspx 22Dec2015
Accounts Accounts Page Accounts.aspx 29Dec2015
When i run the above code output as follows
22Dec2015
Defects
Defects page
Defects.aspx
22Dec2015
Accounts
Accounts Page
Accounts.aspx
But i want the output as follows in the run mode as follows
22Dec2015 Defects Defects page Defects.aspx
22Dec2015 Accounts Accounts page Accounts.aspx
for that how can i do in asp.net using c#.
string myConString = ConfigurationManager.ConnectionStrings["Reception2_DB"].ConnectionString;
using (SqlConnection conn = new SqlConnection(myConString))
{
string query;
query = Select Subject,Description,Link,Entereddate from LatestNewsMaster and active <>'d'";
SqlCommand cmd = new SqlCommand(query, conn);
conn.Open();
using (SqlDataReader rdr = cmd.ExecuteReader())
{
while (rdr.Read())
{
sbNews.Append(rdr[3].ToString() + "
");
sbNews.Append(rdr[0].ToString() + "
");
sbNews.Append(rdr[1].ToString() + "
");
sbNews.Append(rdr[2].ToString() + "
");
}
}
NewsTicker = sbNews.ToString();
}
In database record as follows
Subject Description Link entereddate
Defects Defects page Defects.aspx 22Dec2015
Accounts Accounts Page Accounts.aspx 29Dec2015
When i run the above code output as follows
22Dec2015
Defects
Defects page
Defects.aspx
22Dec2015
Accounts
Accounts Page
Accounts.aspx
But i want the output as follows in the run mode as follows
22Dec2015 Defects Defects page Defects.aspx
22Dec2015 Accounts Accounts page Accounts.aspx
for that how can i do in asp.net using c#.
Akhil GargPosted Jan 4, 2016, 9:10 PM
Rajeev PunhaniPosted Jan 4, 2016, 12:28 PM
Raja TPosted Jan 4, 2016, 11:41 AM
http://mobile.databasejournal.com/features/mssql/converting-rows-to-columns-pivot-and-columns-to-rows-unpivot-in-sql-server.html
http://blog.devart.com/is-unpivot-the-best-way-for-converting-columns-into-rows.html
http://stackoverflow.com/questions/13372276/simple-way-to-transpose-columns-and-rows-in-sql