Sending stored proc Parameter

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Rob

    #1

    Sending stored proc Parameter

    What is the syntax to send a null value as a parameter ?

    cmd.Parameters. Add("@Year", Convert.ToInt32 (strYear))

    in cases where strYear = ""

    I want to send ...

    cmd.Parameters. Add("@Year", Null)

    But the syntax is incorrect....

    How would I send it ?


  • rowe_newsgroups

    #2
    Re: Sending stored proc Parameter

    On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.co mwrote:
    What is the syntax to send a null value as a parameter ?
    >
    cmd.Parameters. Add("@Year", Convert.ToInt32 (strYear))
    >
    in cases where strYear = ""
    >
    I want to send ...
    >
    cmd.Parameters. Add("@Year", Null)
    >
    But the syntax is incorrect....
    >
    How would I send it ?
    Will it accept DbNull?

    Thanks,

    Seth Rowe

    Comment

    • Rob

      #3
      Re: Sending stored proc Parameter

      No, I tried that as well, but it did not like that either...

      Thanks
      Rob


      "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
      news:1186503805 .372190.4910@22 g2000hsm.google groups.com...
      On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.co mwrote:
      >What is the syntax to send a null value as a parameter ?
      >>
      >cmd.Parameters .Add("@Year", Convert.ToInt32 (strYear))
      >>
      >in cases where strYear = ""
      >>
      >I want to send ...
      >>
      >cmd.Parameters .Add("@Year", Null)
      >>
      >But the syntax is incorrect....
      >>
      >How would I send it ?
      >
      Will it accept DbNull?
      >
      Thanks,
      >
      Seth Rowe
      >

      Comment

      • Bill McCarthy

        #4
        Re: Sending stored proc Parameter

        Hi Rob,

        Did you try DbNull.Value ?

        Regards,
        Bill.


        "Rob" <robc1@yahoo.co mwrote in message
        news:EPadnZqc-p3EPSXbnZ2dnUVZ _h-vnZ2d@comcast.c om...
        No, I tried that as well, but it did not like that either...
        >
        Thanks
        Rob
        >
        >
        "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
        news:1186503805 .372190.4910@22 g2000hsm.google groups.com...
        >On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.co mwrote:
        >>What is the syntax to send a null value as a parameter ?
        >>>
        >>cmd.Parameter s.Add("@Year", Convert.ToInt32 (strYear))
        >>>
        >>in cases where strYear = ""
        >>>
        >>I want to send ...
        >>>
        >>cmd.Parameter s.Add("@Year", Null)
        >>>
        >>But the syntax is incorrect....
        >>>
        >>How would I send it ?
        >>
        >Will it accept DbNull?
        >>
        >Thanks,
        >>
        >Seth Rowe
        >>
        >
        >

        Comment

        • Armin Zingler

          #5
          Re: Sending stored proc Parameter

          "Rob" <robc1@yahoo.co mschrieb
          What is the syntax to send a null value as a parameter ?
          >
          cmd.Parameters. Add("@Year", Convert.ToInt32 (strYear))
          >
          in cases where strYear = ""
          >
          I want to send ...
          >
          cmd.Parameters. Add("@Year", Null)
          >
          But the syntax is incorrect....
          >
          How would I send it ?
          'untested, without string validation:
          shared function ABC(byval s as string) as object

          if s.length=0 then return dbnull.value
          return cint(s)

          end function

          cmd.Parameters. Add("@Year", ABC(strYear))


          Armin

          Comment

          • Rob

            #6
            Re: Sending stored proc Parameter

            Thanks Bill,

            Yes, looks like that will work... I should have known...

            Rob


            "Bill McCarthy" <Bill@NOSPAM.co mwrote in message
            news:O9wFGLR2HH A.1100@TK2MSFTN GP06.phx.gbl...
            Hi Rob,
            >
            Did you try DbNull.Value ?
            >
            Regards,
            Bill.
            >
            >
            "Rob" <robc1@yahoo.co mwrote in message
            news:EPadnZqc-p3EPSXbnZ2dnUVZ _h-vnZ2d@comcast.c om...
            >No, I tried that as well, but it did not like that either...
            >>
            >Thanks
            >Rob
            >>
            >>
            >"rowe_newsgrou ps" <rowe_email@yah oo.comwrote in message
            >news:118650380 5.372190.4910@2 2g2000hsm.googl egroups.com...
            >>On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.co mwrote:
            >>>What is the syntax to send a null value as a parameter ?
            >>>>
            >>>cmd.Paramete rs.Add("@Year", Convert.ToInt32 (strYear))
            >>>>
            >>>in cases where strYear = ""
            >>>>
            >>>I want to send ...
            >>>>
            >>>cmd.Paramete rs.Add("@Year", Null)
            >>>>
            >>>But the syntax is incorrect....
            >>>>
            >>>How would I send it ?
            >>>
            >>Will it accept DbNull?
            >>>
            >>Thanks,
            >>>
            >>Seth Rowe
            >>>
            >>
            >>
            >

            Comment

            • =?ISO-8859-1?Q?G=F6ran_Andersson?=

              #7
              Re: Sending stored proc Parameter

              Rob wrote:
              What is the syntax to send a null value as a parameter ?
              >
              cmd.Parameters. Add("@Year", Convert.ToInt32 (strYear))
              >
              in cases where strYear = ""
              >
              I want to send ...
              >
              cmd.Parameters. Add("@Year", Null)
              >
              But the syntax is incorrect....
              >
              How would I send it ?
              >
              You create a parameter with the correct type and set the value to DBNull:

              cmd.Parameters. Add("@Year", SqlDbType.Int). Value = DBNull.Value

              --
              Göran Andersson
              _____
              Göran Anderssons privata hemsida.

              Comment

              • Bill McCarthy

                #8
                Re: Sending stored proc Parameter

                No problem Rob, it catches me out plenty of times <g>


                "Rob" <robc1@yahoo.co mwrote in message
                news:9IydnTp0Hq BNMSXbnZ2dnUVZ_ j-dnZ2d@comcast.c om...
                Thanks Bill,
                >
                Yes, looks like that will work... I should have known...
                >
                Rob
                >
                >
                "Bill McCarthy" <Bill@NOSPAM.co mwrote in message
                news:O9wFGLR2HH A.1100@TK2MSFTN GP06.phx.gbl...
                >Hi Rob,
                >>
                >Did you try DbNull.Value ?
                >>
                >Regards,
                >Bill.
                >>
                >>
                >"Rob" <robc1@yahoo.co mwrote in message
                >news:EPadnZq c-p3EPSXbnZ2dnUVZ _h-vnZ2d@comcast.c om...
                >>No, I tried that as well, but it did not like that either...
                >>>
                >>Thanks
                >>Rob
                >>>
                >>>
                >>"rowe_newsgro ups" <rowe_email@yah oo.comwrote in message
                >>news:11865038 05.372190.4910@ 22g2000hsm.goog legroups.com...
                >>>On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.co mwrote:
                >>>>What is the syntax to send a null value as a parameter ?
                >>>>>
                >>>>cmd.Paramet ers.Add("@Year" , Convert.ToInt32 (strYear))
                >>>>>
                >>>>in cases where strYear = ""
                >>>>>
                >>>>I want to send ...
                >>>>>
                >>>>cmd.Paramet ers.Add("@Year" , Null)
                >>>>>
                >>>>But the syntax is incorrect....
                >>>>>
                >>>>How would I send it ?
                >>>>
                >>>Will it accept DbNull?
                >>>>
                >>>Thanks,
                >>>>
                >>>Seth Rowe
                >>>>
                >>>
                >>>
                >>
                >
                >

                Comment

                • rowe_newsgroups

                  #9
                  Re: Sending stored proc Parameter

                  On Aug 7, 12:48 pm, "Bill McCarthy" <B...@NOSPAM.co mwrote:
                  Hi Rob,
                  >
                  Did you try DbNull.Value ?
                  >
                  Regards,
                  Bill.
                  >
                  "Rob" <ro...@yahoo.co mwrote in message
                  >
                  news:EPadnZqc-p3EPSXbnZ2dnUVZ _h-vnZ2d@comcast.c om...
                  >
                  >
                  >
                  No, I tried that as well, but it did not like that either...
                  >
                  Thanks
                  Rob
                  >
                  "rowe_newsgroup s" <rowe_em...@yah oo.comwrote in message
                  news:1186503805 .372190.4910@22 g2000hsm.google groups.com...
                  On Aug 7, 12:19 pm, "Rob" <ro...@yahoo.co mwrote:
                  >What is the syntax to send a null value as a parameter ?
                  >
                  >cmd.Parameters .Add("@Year", Convert.ToInt32 (strYear))
                  >
                  >in cases where strYear = ""
                  >
                  >I want to send ...
                  >
                  >cmd.Parameters .Add("@Year", Null)
                  >
                  >But the syntax is incorrect....
                  >
                  >How would I send it ?
                  >
                  Will it accept DbNull?
                  >
                  Thanks,
                  >
                  Seth Rowe- Hide quoted text -
                  >
                  - Show quoted text -
                  Thats what I meant - do I get partial credit for saying DbNull?

                  :-)

                  Thanks,

                  Seth Rowe

                  Comment

                  • Bill McCarthy

                    #10
                    Re: Sending stored proc Parameter

                    Hi Seth,

                    Sure do :) For some reason I always look for DbNull.Default only to realize
                    it's DbNull.Value I need.

                    "rowe_newsgroup s" <rowe_email@yah oo.comwrote in message
                    news:1186513142 .077123.207070@ x40g2000prg.goo glegroups.com.. .
                    >
                    Thats what I meant - do I get partial credit for saying DbNull?
                    >
                    :-)
                    >
                    Thanks,
                    >
                    Seth Rowe
                    >

                    Comment

                    Working...