Question

How can I get information from my datable?

I just want to get column from start to finish, and load them to textboxes.text.

ClienteHolder.IDCliente = Tabla.Rows[]?????
Was it helpful?

Solution

Tabla.Rows[0]["mycolumnName"]

This is how you can refer to a single column. What do you mean by column from start to finish?

What are the controls that you wish to store each of the column's value in?

OTHER TIPS

generally, you access the tables collection of the dataset, then access the rows collection of the table. Like this:

myDataSet.Tables[0] // you can also use the name of the table, instead of an integer 

myTable.Rows[ n ]   // this will give you the nth row in the table

myRow[ n ]          // this will give you the nth column in the row, you can use the
                    // name of the column instead of an integer

this will iterate through all the columns in all the rows from all the tables in the dataset.

foreach( DataTable curTable in myDataSet.Tables )
{
     foreach( DataRow curRow in curTable.Rows )
     {
          foreach( DataColumn curCol in Table.Columns )
          {
               object item = curRow[ curCol ];
          }
     }
}

The Rows property for a datatable is IEnumerable. LINQ is the better way to go here, but here's the way I do it with a foreach loop (If I'm understanding your question correctly.)

I just want to get column from start to finish, and load them to textboxes.text.

foreach(System.DataRow dr in Tabla.Rows)//iterate rows
{
    foreach(System.DataColumn dc in Tabla.Columns)  //iterate columns per row
    {
        textboxes.text = dr[dc].ToString();  //get object value at row,column
    }
}

LINQ would be lamda like and awesome, but alas, We don't use 3.x here yet so I'm stuck leaning on this method.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top