Returning a single row in a strongly typed DataSet in C#
I have a Strongly typed Dataset TableAdapter in C#, how do 开发者_StackOverflow社区I get a single row from it?
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"];
You can try:
myTableAdapter[0];
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();
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;
精彩评论