Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

StackOverflow Point

StackOverflow Point Navigation

  • Web Stories
  • Badges
  • Tags
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Web Stories
  • Badges
  • Tags
Home/ Questions/Q 185831
Alex Hales
  • 0
Alex HalesTeacher
Asked: June 10, 20222022-06-10T07:52:42+00:00 2022-06-10T07:52:42+00:00

asp.net – Fetch Data Between Two Dates in VB.NET from SQL Server by giving multiple parameter like @customerNo, @registraionNo

  • 0

[ad_1]

Here is my VB.NET code

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:

Data Has Not Been Found

and in VB Code no exception thrown.
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

Can anyone tell me what I am doing wrong here?

Thanks

[ad_2]

  • 0 0 Answers
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

Sidebar

Ask A Question

Related Questions

  • xcode - Can you build dynamic libraries for iOS and ...

    • 0 Answers
  • bash - How to check if a process id (PID) ...

    • 396 Answers
  • database - Oracle: Changing VARCHAR2 column to CLOB

    • 370 Answers
  • What's the difference between HEAD, working tree and index, in ...

    • 361 Answers
  • Amazon EC2 Free tier - how many instances can I ...

    • 0 Answers

Stats

  • Questions : 43k

Subscribe

Login

Forgot Password?

Footer

Follow

© 2022 Stackoverflow Point. All Rights Reserved.

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.