我在C#中有一个强类型数据集TableAdapter,如何从中获取单行?
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"];
你可以试试:
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 (ie 'WHERE ID = @id') and call that instead of the default GetData method:
var table = tableAdapter.GetDataById(123);
var resultRow = table.Rows.First;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.