我在 VB.net 中编程。我正在尝试通过针对我的数据库搜索电子邮件地址来填充 2 个 gridview 表。当用户单击搜索按钮时,我希望我的程序从文本框中获取值,根据我的数据库搜索电子邮件地址,然后在我的“ScrumMaster”表和“开发人员”表中显示用户配置文件。我不知道如何在一个“btnSearchEmail_Click”方法中实现所有这些。目前我拥有的代码是
Protected Sub btnSearchEmail_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSearchEmail.Click
End Sub
Protected Sub ScrumMastersDataSource_Selecting(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles ScrumMastersDataSource.Selecting
Dim db As New AgileClassesDataContext()
Dim enteredEmail = txtEnteredEmail.Text
Dim scrumMasters = (From u In db.Users
Join ur In db.UserRoles On u.UserId Equals ur.UserId
Join r In db.Roles On ur.RoleId Equals r.RoleId
Where r.RoleId = 2 And u.Email = enteredEmail
Select u).Distinct
e.Result = scrumMasters
End Sub
Protected Sub DevelopersDataSource_Selecting(sender As Object, e As System.Web.UI.WebControls.LinqDataSourceSelectEventArgs) Handles DevelopersDataSource.Selecting
Dim db As New AgileClassesDataContext()
Dim enteredEmail = txtEnteredEmail.Text
Dim developers = (From u In db.Users
Join ur In db.UserRoles On u.UserId Equals ur.UserId
Join r In db.Roles On ur.RoleId Equals r.RoleId
Where r.RoleId = 3 And u.Email = enteredEmail
Select u).Distinct
e.Result = developers
End Sub
如您所见,这里有 3 种方法。我想将“ScrumMastersDataSource_Selecting”和“DevelopersDataSource_Selecting”放在“btnSearchEmail_Click”事件中,以便在单击“btnSearchEmail”时它们都运行。由于电子邮件地址可能与开发人员和 Scrum Master 角色相关联,因此重复不是问题。任何的建议都受欢迎。我希望这个问题有意义