使用VB字段的SQL查询不会返回结果

时间:2015-03-24 04:52:36

标签: sql-server visual-studio-2010

我已经尝试了几个小时来找出使用字段的MSSQL查询的正确语法。如果我使用第一行代码,我就没有结果。

Dim selectStatement As String = "SELECT * from tires.dbo.sales WHERE date BETWEEN '" & Reports.CalStartDate.SelectionStart & "'" & " and " & Reports.CalEndDate.SelectionEnd & "'"""

(我有两个显示Reports.CalStartDate.SelectionStartReports.CalStartDate.SelectionEnd内容的文本框,它们显示正确的字符,与有效的查询完全相同。

如果我使用此(硬编码)行,我会得到预期的结果。

Dim selectStatement As String = "SELECT * from tires.dbo.sales where date between '03/21/2015' and'03/23/2015'"

这是我的mssql创建脚本:

USE [tires]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[sales](
[date] [date] NULL,
[cust_id] [int] NULL,
[tire_id] [int] NULL,
[qty] [int] NULL,
[cost_ea] [decimal](5, 2) NULL,
[retail_ea] [decimal](5, 2) NULL,
[plate] [nchar](10) NULL,
[mileage] [nchar](10) NULL,
[service] [nchar](30) NULL,
[serv_price] [nchar](10) NULL,
[total] [nchar](10) NULL,
[notes] [nvarchar](150) NULL,
[custphone] [nchar](10) NULL,
[service2] [nchar](30) NULL,
[serv2_price] [nchar](10) NULL,
[inv_no] [int] IDENTITY(1,1) NOT NULL,
[tire_id2] [int] NULL,
[qty2] [int] NULL,
[cost_ea2] [decimal](5, 2) NULL,
[retail_ea2] [decimal](5, 2) NULL,
[tire_id3] [int] NULL,
[qty3] [int] NULL,
[cost_ea3] [decimal](5, 2) NULL,
[retail_ea3] [decimal](5, 2) NULL,
[tire1w] [nvarchar](50) NULL,
[tire2w] [nvarchar](50) NULL,
[tire3w] [nvarchar](50) NULL,
[tax] [nchar](10) NULL,
[fet] [nchar](10) NULL,
[labor] [nchar](10) NULL,
CONSTRAINT [PK_sales] PRIMARY KEY CLUSTERED 
(
[inv_no] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF,       ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON) ON [PRIMARY]
) ON [PRIMARY]
GO

0 个答案:

没有答案