1

while I was trying to convert my Database to a Datatable, I found information about about how to add Columns to a Database. The Code looked a little like this:

string it;
DataTable another_tranTab = new DataTable();
another_tranTab.Columns.Add("Column1", typeof(String)); 
int a = 0;
int b = 0;

while (a < tranTable.Rows.Count)
{
    it = Convert.ToString(tranTable.Rows[a][0]);
    if (it == "False")
    {
        DataRow newRow = another_tranTab.NewRow();
        newRow["Column1"] = a;
        another_tranTab.Rows.Add(newRow);
        b = b + 1;
    }
    a++;
}

My question is what this part stands for it = Convert.ToString(tranTable.Rows[a][0]); I don't really understand what the [0] stands for.

diiN__________
  • 7,393
  • 6
  • 42
  • 69
MaChaToc
  • 139
  • 1
  • 12
  • I think [0] means column1 of datatable and a is the row of datatable. – sowjanya attaluri Jun 20 '16 at 13:26
  • Just curious if you are using ADO.net to query the data base you could use a SQLdataAdapter to fill a data table automatically unless there is some strange constraints on your data. Shown here, http://stackoverflow.com/questions/6073382/read-sql-table-into-c-sharp-datatable – Bearcat9425 Jun 20 '16 at 13:27
  • Rows[a][0]]- Rows[rowindex][Columnindex] – krish Jun 20 '16 at 13:29

1 Answers1

0
Columns     0          1               2 

           Name       City            Age

   Row 0   Guilherme  Pres. Prud.     23

   Row 1   Lucas      São Paulo       18

   Row 2   Pedro      Rio de Janeiro  35

How do I get city from Pedro?

I must get the line 2 and col 1.

Then: dataTable[1][2]. //dataTable[col1][row2].
  • Thanks, the answer was quite easier than I thought :) I am not quite sure what you mean with ADO.net, I am doing this with a Windows Form Application with Visual Studio (.NET). My actual goal is to fill a groupbox with buttons and each button shall stand for one entry from my Sql-Database which already exists – MaChaToc Jun 20 '16 at 14:01