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. Other Discussions
  3. The Weird and The Wonderful
  4. Constant Headache

Constant Headache

Scheduled Pinned Locked Moved The Weird and The Wonderful
databasecom
12 Posts 6 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.
  • A Offline
    A Offline
    AspDotNetDev
    wrote on last edited by
    #1

    Found this little nugget just now (only the name of the stored procedure was changed):

    Dim strSelect As String = "exec SomeStoredProcedure " & 1

    :doh:

    Thou mewling ill-breeding pignut!

    E Z 2 Replies Last reply
    0
    • A AspDotNetDev

      Found this little nugget just now (only the name of the stored procedure was changed):

      Dim strSelect As String = "exec SomeStoredProcedure " & 1

      :doh:

      Thou mewling ill-breeding pignut!

      E Offline
      E Offline
      ekolis
      wrote on last edited by
      #2

      Well, at least it's not vulnerable to SQL injection...

      A 1 Reply Last reply
      0
      • E ekolis

        Well, at least it's not vulnerable to SQL injection...

        A Offline
        A Offline
        AspDotNetDev
        wrote on last edited by
        #3

        I suspect the original was, and the constant was put in there when a variable was no longer required, but they didn't want to put in the extra effort of placing the constant inside the string. :doh:

        Thou mewling ill-breeding pignut!

        1 Reply Last reply
        0
        • A AspDotNetDev

          Found this little nugget just now (only the name of the stored procedure was changed):

          Dim strSelect As String = "exec SomeStoredProcedure " & 1

          :doh:

          Thou mewling ill-breeding pignut!

          Z Offline
          Z Offline
          ZurdoDev
          wrote on last edited by
          #4

          Could have been worse. It could have been C# and then you would have to do

          String strSelect = "exec SomeStoredProcedure " + "1";

          At least VB allows the 1 to be concatenated into the string.

          There are only 10 types of people in the world, those who understand binary and those who don't.

          A B 2 Replies Last reply
          0
          • Z ZurdoDev

            Could have been worse. It could have been C# and then you would have to do

            String strSelect = "exec SomeStoredProcedure " + "1";

            At least VB allows the 1 to be concatenated into the string.

            There are only 10 types of people in the world, those who understand binary and those who don't.

            A Offline
            A Offline
            AspDotNetDev
            wrote on last edited by
            #5

            ryanb31 wrote:

            At least VB allows the 1 to be concatenated into the string.

            Which is completely terrible that it allows you to do that. I also came across some code the other day that said something like this:

            Dim str As String = "blah" & i + 1

            In C#, you'd do this:

            string str = "blah" + (i + 1).ToString();

            Which I think is much more understandable.

            Thou mewling ill-breeding pignut!

            J A 2 Replies Last reply
            0
            • Z ZurdoDev

              Could have been worse. It could have been C# and then you would have to do

              String strSelect = "exec SomeStoredProcedure " + "1";

              At least VB allows the 1 to be concatenated into the string.

              There are only 10 types of people in the world, those who understand binary and those who don't.

              B Offline
              B Offline
              BobJanova
              wrote on last edited by
              #6

              Uh, what. No you don't. String concatenation in C# automatically calls ToString on non-string arguments, including basic types. I use this quite frequently for generating temporary debug output.

              1 Reply Last reply
              0
              • A AspDotNetDev

                ryanb31 wrote:

                At least VB allows the 1 to be concatenated into the string.

                Which is completely terrible that it allows you to do that. I also came across some code the other day that said something like this:

                Dim str As String = "blah" & i + 1

                In C#, you'd do this:

                string str = "blah" + (i + 1).ToString();

                Which I think is much more understandable.

                Thou mewling ill-breeding pignut!

                J Offline
                J Offline
                Jorgen Andersson
                wrote on last edited by
                #7

                Implicit conversions works equally well in VB and C#, AFAIK. I would obviously use paratheses and ToString in VB as well, for clarity purposes. It's basically as easy to code badly in C# as it is in VB. In the end it's up to you.

                Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                A 2 Replies Last reply
                0
                • J Jorgen Andersson

                  Implicit conversions works equally well in VB and C#, AFAIK. I would obviously use paratheses and ToString in VB as well, for clarity purposes. It's basically as easy to code badly in C# as it is in VB. In the end it's up to you.

                  Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                  A Offline
                  A Offline
                  AspDotNetDev
                  wrote on last edited by
                  #8

                  C# does not implicitly convert integers to strings.

                  Thou mewling ill-breeding pignut!

                  1 Reply Last reply
                  0
                  • A AspDotNetDev

                    ryanb31 wrote:

                    At least VB allows the 1 to be concatenated into the string.

                    Which is completely terrible that it allows you to do that. I also came across some code the other day that said something like this:

                    Dim str As String = "blah" & i + 1

                    In C#, you'd do this:

                    string str = "blah" + (i + 1).ToString();

                    Which I think is much more understandable.

                    Thou mewling ill-breeding pignut!

                    A Offline
                    A Offline
                    Ankush Bansal
                    wrote on last edited by
                    #9

                    "In C#, you'd do this:" Well i guess this is much better you know :laugh: string s = "blah" + ((i<<1)- --i);

                    1 Reply Last reply
                    0
                    • J Jorgen Andersson

                      Implicit conversions works equally well in VB and C#, AFAIK. I would obviously use paratheses and ToString in VB as well, for clarity purposes. It's basically as easy to code badly in C# as it is in VB. In the end it's up to you.

                      Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                      A Offline
                      A Offline
                      AspDotNetDev
                      wrote on last edited by
                      #10

                      Well I'll be a monkey's uncle. I just tried it and C# does allow integers to be implicitly converted to strings. Oh well, at least it does not allow the reverse.

                      Thou mewling ill-breeding pignut!

                      J 1 Reply Last reply
                      0
                      • A AspDotNetDev

                        Well I'll be a monkey's uncle. I just tried it and C# does allow integers to be implicitly converted to strings. Oh well, at least it does not allow the reverse.

                        Thou mewling ill-breeding pignut!

                        J Offline
                        J Offline
                        Jorgen Andersson
                        wrote on last edited by
                        #11

                        That's a relief, I'm not senile just yet. On the other hand, I just had to check MSDN, where the C# reference claims that there is a predefined implicit conversion from int to long, float, double, or decimal[^], no mention of strings. Don't you just love their documentation.

                        Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                        A 1 Reply Last reply
                        0
                        • J Jorgen Andersson

                          That's a relief, I'm not senile just yet. On the other hand, I just had to check MSDN, where the C# reference claims that there is a predefined implicit conversion from int to long, float, double, or decimal[^], no mention of strings. Don't you just love their documentation.

                          Light moves faster than sound. That is why some people appear bright, until you hear them speak. List of common misconceptions

                          A Offline
                          A Offline
                          AspDotNetDev
                          wrote on last edited by
                          #12

                          Yeah, I can't find a reference to this anywhere aside from online forums. It would be neat if there's a way to disable it (like VB's option strict).

                          Thou mewling ill-breeding pignut!

                          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