Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Nullable datatyped and coalesce

Nullable datatyped and coalesce

Scheduled Pinned Locked Moved C#
helpcsharpsharepointsalesquestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • D Offline
    D Offline
    DIPAK EMSYS
    wrote on last edited by
    #1

    Hi all i am using Coalesce function in sqlserver 2005 following is sp ALTER PROCEDURE [dbo].[GetAllBillDetails] ( @FromDate AS DATETIME, @ToDate AS DATETIME ) AS BEGIN DECLARE @Err int SELECT BillNo, SalesDate, CustName, Address, Discount, TotalAmount, NetPayable FROM Sales WHERE SalesDate BETWEEN COALESCE(@FromDate,SalesDate) AND COALESCE(@ToDate,SalesDate) SET @Err = @@Error RETURN @Err END following is code to in C# to call this sp private void BindGrid() { SqlCommand command = new SqlCommand("GetAllBillDetails", sqlConn); SqlDataAdapter ada = new SqlDataAdapter(); DataSet dataSet = new DataSet("Master"); ada.TableMappings.Add("Table", "Master"); command.CommandType = CommandType.StoredProcedure; DateTime? fdate; DateTime? todate; fdate = dtpFromDate.Value.Date; todate = dtpToDate.Value.Date; if (!dtpFromDate.Checked) { fdate = null; } if (!dtpToDate.Checked) { todate = null; } command.Parameters.Add(new SqlParameter("@FromDate", fdate)); command.Parameters.Add(new SqlParameter("@ToDate", todate)); ada.SelectCommand = command; ada.Fill(dataSet); } It is giving me error like procedure or function GetAllBillDetails requires parameter @FromDate which was not supplied. Can any one help me to solve this issue... Dipak Thesiya DRC Pvt Ltd...:confused:

    dipak

    C 1 Reply Last reply
    0
    • D DIPAK EMSYS

      Hi all i am using Coalesce function in sqlserver 2005 following is sp ALTER PROCEDURE [dbo].[GetAllBillDetails] ( @FromDate AS DATETIME, @ToDate AS DATETIME ) AS BEGIN DECLARE @Err int SELECT BillNo, SalesDate, CustName, Address, Discount, TotalAmount, NetPayable FROM Sales WHERE SalesDate BETWEEN COALESCE(@FromDate,SalesDate) AND COALESCE(@ToDate,SalesDate) SET @Err = @@Error RETURN @Err END following is code to in C# to call this sp private void BindGrid() { SqlCommand command = new SqlCommand("GetAllBillDetails", sqlConn); SqlDataAdapter ada = new SqlDataAdapter(); DataSet dataSet = new DataSet("Master"); ada.TableMappings.Add("Table", "Master"); command.CommandType = CommandType.StoredProcedure; DateTime? fdate; DateTime? todate; fdate = dtpFromDate.Value.Date; todate = dtpToDate.Value.Date; if (!dtpFromDate.Checked) { fdate = null; } if (!dtpToDate.Checked) { todate = null; } command.Parameters.Add(new SqlParameter("@FromDate", fdate)); command.Parameters.Add(new SqlParameter("@ToDate", todate)); ada.SelectCommand = command; ada.Fill(dataSet); } It is giving me error like procedure or function GetAllBillDetails requires parameter @FromDate which was not supplied. Can any one help me to solve this issue... Dipak Thesiya DRC Pvt Ltd...:confused:

      dipak

      C Offline
      C Offline
      Colin Angus Mackay
      wrote on last edited by
      #2

      Try passing System.DBNull.Value rather than just null.


      Upcoming FREE developer events: * Developer Day Scotland My website

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups