Orhan Cinar
Orhan Cinar

Reputation: 8410

Returning a single row in a strongly typed DataSet in C#

I have a Strongly typed Dataset TableAdapter in C#, how do I get a single row from it?

Upvotes: 5

Views: 4264

Answers (4)

Jens Ehrich
Jens Ehrich

Reputation: 651

You can also create an additional parameterized query (i.e. 'WHERE ID = @id') and call that instead of the default GetData method:

var table = tableAdapter.GetDataById(123); 
var resultRow = table.Rows.First; 

Upvotes: 1

Kris van der Mast
Kris van der Mast

Reputation: 16613

You can try:

myTableAdapter[0];

Upvotes: 1

Lee
Lee

Reputation: 144206

var table = tableAdapter.GetData();
var resultRow = table.Rows[0];

EDIT: Strongly-typed datasets create a property for each column in the table, so to get the Id, this should work:

int id = resultRow.Id

You can also get fields by name:

int id = (int)resultRow["id"];

Upvotes: 4

Orhan Cinar
Orhan Cinar

Reputation: 8410

       var ta = new AddressTableAdapter();

       var ret = ta.GetDataBy(Convert.ToInt32(ASPxTextBox1.Text));
       var rw = ret.Rows[0];

       var city = (string)rw["City"];


       ASPxTextBox2.Text = city.ToString();

Upvotes: 0

Related Questions