C# .NET - How To Get All Values of rows of data table in a string using C#

Asked By Gulam Hussain on 05-Feb-11 02:20 AM
Hello Friends ,

  i m new on C# .Net . i got all the values from table into data table and i want to show all the rows value as text.
please help me to show all rows value as text or string.

thanks
Reena Jain replied to Gulam Hussain on 05-Feb-11 02:49 AM
hi,

just use loop for rows in datatable and add the rows column's value in string like this

String ShowAll="";
// SQL Select Command
SqlCommand mySqlSelect = new SqlCommand("select * from categories", mySQLconnection);
mySqlSelect.CommandType = CommandType.Text;
SqlDataAdapter mySqlAdapter = new SqlDataAdapter(mySqlSelect);
DataTable dt= new DataTable ();
mySqlAdapter.Fill(dt);
if(dt.rows.count >0)
{
for(int i=0; i<=dt.rows.count; i++)
{
ShowAll=ShowAll + dt.rows["Column1"].Tostring() + "," + dt.rows["Column2"].Tostring(); + ";"
}
}

hope this will help you
Gulam Hussain replied to Reena Jain on 05-Feb-11 03:28 AM
Thank a lot Dear Friend.

 I used your code with some changes.

thanks friend.