这是我用我的查询设置的一个函数,它试图检索用户可能会或可能不会输入到几个文本框中的特定信息。用户可以在...
- 公司名称
- 客户名字
- 技术人员的名字
我想要的是,如果用户没有在文本框中输入任何内容,那么查询将返回所有字段,例如“*”,我相信 LINQ 使用和 SQL 使用“%”。我已经尝试了这两种方法,但无法弄清楚为什么我无法检索一家拥有所有客户和所有技术人员的公司。
Public Function SpecificQueryInvoices(ByVal Company As String, ByVal Clientname As String, ByVal techname As String)
Dim specificQuerySetInformation = From invo In database.Invoices
Join orgs In database.Organizations
On orgs.OrgId Equals invo.OrgId
Join clien In database.Clients
On clien.ClientId Equals invo.ClientId
Join tec In database.Teches
On tec.TechId Equals invo.TechId
Order By invo.InvoiceId
Where orgs.OrgName.StartsWith(Company) And clien.FirstName.StartsWith(Clientname) And tec.FirstName.StartsWith(techname)
Select New With {.Company = orgs.OrgName, .Client = clien.FirstName, _
.Tech = tec.FirstName, invo.Date, _
invo.Notes, invo.Parts, invo.Labor, invo.Mileage, invo.TotalCost, _
invo.InvoiceNumber}
Return specificQuerySetInformation
End Function
Private Sub btnFilter_Click(sender As System.Object, e As System.EventArgs) Handles btnFilter.Click
Dim companyName As String
Dim ClientFirstName As String
Dim TechFirstName As String
If txtCompany.Text = "" Then
companyName = "*"
Else
companyName = txtCompany.Text
End If
If txtClientName.Text = "" Then
ClientFirstName = "*"
Else
ClientFirstName = txtClientName.Text
End If
If txtTechName.Text = "" Then
TechFirstName = "*"
Else
TechFirstName = txtTechName.Text
End If
DataGridView2.DataSource = SpecificQueryInvoices(companyName, ClientFirstName, TechFirstName)
MsgBox("Filter requested")
End Sub