开发者

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

开发者 https://www.devze.com 2023-01-04 17:42 出处:网络
I have a Strongly typed Dataset TableAdapter in C#, how do 开发者_StackOverflow社区I get a single row from it?var table = tableAdapter.GetData();

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; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号