Jessie Giliur
Jessie Giliur

Reputation: 21

Use a returned datatable

I have two classes. I created a datatable in class 2 that gets returned. I am trying to figure out how I can use these values in class 1. I need to pass the datatable value in another method in class 1.

//Example: In Class 2 I have:

public Datatable Mytable()
{         
    DataTable table = new DataTable(); 

table.Columns.Add("Column1", typeof(string)); 

table.Columns.Add("Column2", typeof(string)); 

      //get values for the data row here

return table;
}

In Class 1 I have:

public Method1 (String A, String B) 
//A and B need to represent the values in the Datatable from Class 2
{  string ab = "This is first datarow " + A + " This is second datarow " + B;

}

Upvotes: 2

Views: 194

Answers (2)

Dylan Smith
Dylan Smith

Reputation: 22255

public class Class1 {
    public Class1() {
        var foo = new Class2();
        var table = foo.MyTable();
        Method1(table.Rows[0]["Column1"], table.Rows[0]["Column2"]);
    }
}

Upvotes: 1

trailmax
trailmax

Reputation: 35126

I think you need to look up how to use DataTables here: http://www.dotnetperls.com/datatable-foreach

Upvotes: 0

Related Questions