我在一个在范围内工作的应用程序中编写了一个导出(Access to Excel)功能。
用户有4 RadioButtons
:A-F,G-M,N-R和S-Z。
我们假设用户已选择rbtnAF
,这会将所有客户加载到Customer_Code
字段以A,B,C,D,E或F开头的网格中。
加载数据的代码如下:
Dim strFields As String = "[Customer_Addresses].[Cust_Code], [Customers].[Customer_Name], [Customer_Addresses].[Contact_Code], [Customer_Addresses].[Contact_Name], " & _
"[Customer_Addresses].[Contact_Type], [Customer_Addresses].[Add1], [Customer_Addresses].[Add2], [Customer_Addresses].[Add3], [Customer_Addresses].[Add4], " & _
"[Customer_Addresses].[Add5], [Customer_Addresses].[Postcode], [Customer_Addresses].[Country], [Customer_Addresses].[Telephone], [Customer_Addresses].[Fax], " & _
"[Customer_Addresses].[Email], [Customer_Addresses].[Mobile_Phone], [Customers].[Customer_Category], [Customers].[Average_Payment_Terms], " & _
"[Customers].[Notes], [Customers].[salesRep], [Customers].[hoEmail], [Customers].[webpage] FROM Customers " & _
"INNER JOIN Customer_Addresses ON [Customers].[Customer_Code] =[Customer_Addresses].[Cust_Code]"
If rbtnAF.Checked = True Then
sql = "SELECT " & strFields & " WHERE [Customer_Addresses].[Cust_Code] BETWEEN " & _
"'A*' AND 'F*' ORDER BY [Customer_Addresses].[Cust_Code]"
Dim da As New OleDbDataAdapter(sql, con)
Dim ds As New DataSet
Dim dt As New System.Data.DataTable
da.Fill(ds)
dt = ds.Tables(0).Copy()
ugExport.DataSource = Nothing
ugExport.DataSource = dt
我认为这是正常的,我能够将正确的范围加载到网格中并按我的意愿导出它们。 但是,用户已回复我并说它没有加载所有客户。
我认为这有点奇怪,所以我加载了他们的数据库并为自己测试了它。在数据库中,有4个客户符合A-F的范围,如图所示。
但是,当我在导出列表中查看客户范围A-F时,只显示了2个客户。
还值得注意的是,在“客户列表”屏幕中有一个TextBox
允许用户按客户代码进行搜索 - 当我输入一个F时,所有4个客户都显示为预期
在地球上发生什么只显示出口清单中的2个结果,尽管有4个符合标准的记录?
答案 0 :(得分:2)
检查语法之间你会发现它将*视为文字字符,请参阅此处https://support.office.com/en-us/article/Between-And-Operator-a435878d-63f7-4825-8c31-999432ae8223
您可以使用
Like "[A-F]*"
相反。