Reputation: 8410
I have a Strongly typed Dataset TableAdapter in C#, how do I get a single row from it?
Upvotes: 5
Views: 4264
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
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
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