Click here to Skip to main content
15,919,245 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using console application

SqlConnection conn = new SqlConnection("Data Source = dys-srv-102;     Initial Catalog = test; user id = sa; password = vesuvius; persist Security info = True"); 

string sql = "Select name,class,Id from student";
SqlDataAdapter Da = new SqlDataAdapter(sql, conn);
DataSet Ds = new DataSet();
Da.Fill(Ds, "stu");            
Console.ReadLine();


How to print the table, which is in my dataset
Posted
Updated 4-Jan-11 18:26pm
v2

Hope
private void PrintRows(DataSet myDataSet){
   // For each table in the DataSet, print the row values.
   foreach(DataTable myTable in myDataSet.Tables){
      foreach(DataRow myRow in myTable.Rows){
         foreach (DataColumn myColumn in myTable.Columns){
            Console.WriteLine(myRow[myColumn]);
         }
      }
   }
}

this code also help you.
 
Share this answer
 
Comments
dmageiras 5-Jan-11 0:53am    
Good call, 5 from me too! My version keeps it simple, I admit your code is more elegant :)
Tarun.K.S 5-Jan-11 0:55am    
A more generic answer. Have a 5!
Kasson 5-Jan-11 0:56am    
Thanks dmageiras.
Kasson 5-Jan-11 0:56am    
Thanks Tarun
swathi.N 5-Jan-11 1:19am    
thanku
Try something like this:

for (int i = 0 ; i < Ds.Tables[0].Count; i++) {
  Console.Write(Ds.Tables[0].Row[i]["name"]);
  Console.Write(Ds.Tables[0].Row[i]["class"]);
  Console.Write(Ds.Tables[0].Row[i]["id"]);
}
 
Share this answer
 
Comments
Kasson 5-Jan-11 0:42am    
Good Call My 5 for you.
swathi.N 5-Jan-11 1:19am    
yes,its working thanku
Rajesh Anuhya 5-Jan-11 3:47am    
Good Answer
I am sure THIS[^] article will help you regarding.
 
Share this answer
 
Comments
Hiren solanki 5-Jan-11 1:26am    
I was understanding for printing page in physical page from database, So I've posted that link. I was not sure on what OP wanted actually.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900