编写方法以从表中获取ID并从另一个表中返回相关名称 [英] write method to get id from table and return related name from another table
本文介绍了编写方法以从表中获取ID并从另一个表中返回相关名称的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何编写这样的方法:
从数据库的一个表中获取ID,然后从另一个表中选择相关的名字和姓氏,然后返回名字和姓氏以显示在文本框中.
2个表在id上有关系.
感谢
how to write method like this:
get id from one table in DB, then select related firstName and lastname from another table,then return firstname and last name to show in textbox.
2 tables have relationship on id.
thanks
推荐答案
以下是示例代码:
Here is the sample code:
var result = from p in db.table1
join item in db.table2 on p.ID equals item.ID
select new
{
p.ID,
p.FirstName,
p.LastName,
};
foreach (var info in result)
{
textbox1.Text = info.FirstName + info.LastName
}
写以下查询
从table1中选择FirstName,LastName,其中id =(从table2中选择id,其中---您的条件---)
希望对您有帮助
Hi,
write following query
select FirstName,LastName from table1 where id=(select id from table2 where ---your condition---)
hope it will help
从Table1 A的内部联接中选择FName,LName B.ID = A.id上的Table2 B,其中B.ID =''您的ID此处''
之后,从前面通过手动输入该值,然后通过从下拉列表中选择值来手动输入.
select FName,LName from Table1 A inner join Table2 B on B.ID=A.id where B.ID=''your id here ''
after that pass this value from front enter by manually user enter by selecting value from dropdown
这篇关于编写方法以从表中获取ID并从另一个表中返回相关名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文