使用 LINQ2SQL 填充文本框
在我的 Web 表单中,我有文本框和一个单选列表,我需要通过 LINQ2SQL 查询来填充它们。到目前为止,我编写了这个查询来获取将要填充到数据库中的特定记录。
using (dbTestDataContext db = new dbTestDataContext())
{
var query = from r in db.Table1
where r.Code == getCode
select new
{
//Account Info
r.Name,
r.Num,
r.AcctNum,
r.CorpAcct, //Bool
};
};
现在我知道这个查询要获取的记录将只是 1 个唯一记录。我想在这些文本框中显示记录并选择该单选按钮:
tb名称
tbNum
tbAcctNum
rbtnCorpAcct
我应该怎么做?先感谢您!
In my web forms, I have text boxes and one radiolist which I need to populate through a LINQ2SQL query. So far I coded this query to fetch particular records which is going to be populated into the DB.
using (dbTestDataContext db = new dbTestDataContext())
{
var query = from r in db.Table1
where r.Code == getCode
select new
{
//Account Info
r.Name,
r.Num,
r.AcctNum,
r.CorpAcct, //Bool
};
};
Now I know that the record which this query is going to be fetching is gonna be only 1 unique record. I want to show the record in these textboxes and select that radio button:
tbName
tbNum
tbAcctNum
rbtnCorpAcct
How should I do this? Thank you in advance!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
非常简单:
Very simply:
与其他人的回答相同,添加了单选按钮:
Same as others have answered with addition of radio button:
请尝试以下操作:
Try the following:
您需要做的第一件事是从查询中检索单个结果。正如您所写的,您将返回一个 IQueryable 对象,该对象现在存储在变量“query”中
要获取单个对象,请执行以下操作
然后您可以访问该对象的各个属性并像这样分配它们
tbName。文本 = myObject.Name
The first thing you need to do is retrieve a single result from your query. As you have it written, you are returning an IQueryable object which is now stored in the variable "query"
To get a single object, do this
Then you can access the individual properties of that object and assign them like this
tbName.Text = myObject.Name