[英]Fetch Data Between Two Dates in VB.NET from SQL Server by giving multiple parameter like @customerNo, @registraionNo
Here is my VB.NET code这是我的 VB.NET 代码
Public Shared Function SearchRoboCallByDate(datefrom As String, dateto As String, customerNo As String, regNo As String, terminalNo As String) As DataSet
Dim conn As New SqlConnection
Dim cmd As New SqlCommand
Dim adapter As New SqlDataAdapter
Dim ds As New Data.DataSet
conn = New SqlConnection(ConfigurationManager.ConnectionStrings("SQLConnString").ConnectionString)
'conn.ConnectionString = ConfigurationManager.ConnectionStrings("SQLConnString").ConnectionString
adapter.SelectCommand = cmd
ds.DataSetName = "DataSet"
cmd.CommandText = "sp_getRoboAlarmDetailByDate"
cmd.CommandTimeout = 600
cmd.Connection = conn
cmd.CommandType = CommandType.StoredProcedure
cmd.Parameters.AddWithValue("@datefrom", datefrom)
cmd.Parameters.AddWithValue("@dateto", dateto)
cmd.Parameters.AddWithValue("@customerNo", customerNo)
cmd.Parameters.AddWithValue("@regNo", regNo)
cmd.Parameters.AddWithValue("@TerminalNo", terminalNo)
Try
adapter.Fill(ds)
Catch ex As Exception
ds = Nothing
End Try
Return ds
End Function
and below is my stored procedure下面是我的存储过程
ALTER procedure sp_getRoboAlarmDetailByDate
@datefrom datetime = null ,
@dateto datetime = null ,
@customerNo as nvarchar(60) = null ,
@regNo as nvarchar(60) = null,
@TerminalNo as nvarchar(60) = null
as
begin
if(@regNo = '0')
BEGIN
set @regNo = null
end
if(@customerNo = '0')
BEGIN
set @customerNo = null
end
if(@TerminalNo = '0')
BEGIN
set @TerminalNo = null
end
select
ID = 0 ,
rda.RCLogID ,
rda.VehicleID ,
cv.RegistrationNo ,
rda.TerminalNo ,
rda.PollID ,
rda.PacketNo ,
rda.TableNo ,
rda.ServerID ,
rda.ServerName ,
rda.isCallSuccessful ,
rda.Remarks ,
rda.CreatedOn,
c.CustomerID ,
c.CustomerNo
from
RoboCalls_DefuseAlarms_Log rda
Left join CustomersVehicles cv on cv.VehicleId = rda.VehicleID
Left join Customers c on c.CustomerID = cv.CustomerId
where
rda.CreatedOn between @datefrom AND @dateto
and c.CustomerNo = ISNULL(@customerNo, c.CustomerNo)
and RegistrationNo = ISNULL(@regNo, cv.RegistrationNo)
and rda.TerminalNo = ISNULL(@TerminalNo, rda.TerminalNo)
end
When I select from and to date the data shows in a grid view but when I select another parameter like @customerNo
, or, @regNo
the data grid shows an error:当我选择 from 和 to date 时,数据显示在网格视图中,但是当我选择另一个参数(如
@customerNo
或@regNo
时)数据网格显示错误:
Data Has Not Been Found
未找到数据
and in VB Code no exception thrown.并且在 VB 代码中没有抛出异常。 and by giving static value to store procedure the data shown in sql server but giving parameter from VB.NET code with parameters data disappear from Grid
并通过为存储过程提供静态值,显示在 sql server 中的数据,但从 VB.NET 代码中提供参数,参数数据从网格中消失
Can anyone tell me what I am doing wrong here?谁能告诉我我在这里做错了什么?
Thanks谢谢
I Just tried the following Code我刚刚尝试了以下代码
cmd.CommandText = "Exec sp_GetRoboCallAlarmNotChecked '" & dtStart & "' ,'" & dtEnd & "' , '" & customerNo & "' , '" & regNo & "' ,'" & terminalNo & "', '" & notSuccessCheck & "'"
and my work done THANKS我的工作完成了谢谢
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.