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. problem in code

problem in code

Scheduled Pinned Locked Moved C#
helpquestion
8 Posts 5 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.
  • N Offline
    N Offline
    NiloofarNoroozi
    wrote on last edited by
    #1

    hi when i run this code this generate error why? objCommand.Parameters.Add("@nopersoneli", SqlDbType.int).Value =int.parse(txtNoPersoneli.text); thanks a lot

    D H N 3 Replies Last reply
    0
    • N NiloofarNoroozi

      hi when i run this code this generate error why? objCommand.Parameters.Add("@nopersoneli", SqlDbType.int).Value =int.parse(txtNoPersoneli.text); thanks a lot

      D Offline
      D Offline
      DaveyM69
      wrote on last edited by
      #2

      1. What's the error you're getting 2. Should that be @"nopersoneli" ? 3. Should that be txtNoPersoneli.Text ? 4. Does txtNoPersoneli.Text definately contain a valid integer? 4b. Consider getting the integer value before this line by using int.TryParse method.

      Dave
      BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
      Expect everything to be hard and then enjoy the things that come easy. (code-frog)

      H 1 Reply Last reply
      0
      • N NiloofarNoroozi

        hi when i run this code this generate error why? objCommand.Parameters.Add("@nopersoneli", SqlDbType.int).Value =int.parse(txtNoPersoneli.text); thanks a lot

        H Offline
        H Offline
        Harvey Saayman
        wrote on last edited by
        #3

        Firstly "problem in code" is as usefull as BLAH for a subject line! Secondly give us more detail, what exception is thrown? by the looks of things you need to do this...

        objCommand.Parameters.AddWithValue("@nopersoneli", Int32.parse(txtNoPersoneli.Text));

        or

        objCommand.Parameters.Add("@nopersoneli", SqlDbType.Int);
        objCommand.Parameters["@nopersoneli"].Value = Int32.parse(txtNoPersoneli.Text);

        Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

        L 1 Reply Last reply
        0
        • D DaveyM69

          1. What's the error you're getting 2. Should that be @"nopersoneli" ? 3. Should that be txtNoPersoneli.Text ? 4. Does txtNoPersoneli.Text definately contain a valid integer? 4b. Consider getting the integer value before this line by using int.TryParse method.

          Dave
          BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
          Expect everything to be hard and then enjoy the things that come easy. (code-frog)

          H Offline
          H Offline
          Harvey Saayman
          wrote on last edited by
          #4

          DaveyM69 wrote:

          2. Should that be @"nopersoneli" ?

          it seems hes trying to execute a SQL Stored Procedure using SqlCommand... see my reply

          Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

          D 1 Reply Last reply
          0
          • H Harvey Saayman

            Firstly "problem in code" is as usefull as BLAH for a subject line! Secondly give us more detail, what exception is thrown? by the looks of things you need to do this...

            objCommand.Parameters.AddWithValue("@nopersoneli", Int32.parse(txtNoPersoneli.Text));

            or

            objCommand.Parameters.Add("@nopersoneli", SqlDbType.Int);
            objCommand.Parameters["@nopersoneli"].Value = Int32.parse(txtNoPersoneli.Text);

            Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

            L Offline
            L Offline
            leppie
            wrote on last edited by
            #5

            Harvey Saayman wrote:

            by the looks of things you need to do this...

            His code 'structure' is actually correctly and will do the same as both your examples. Note: the Add method returns a IDBParameter.

            xacc.ide - now with TabsToSpaces support
            IronScheme - 1.0 alpha 4a out now (29 May 2008)
            ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

            H 1 Reply Last reply
            0
            • H Harvey Saayman

              DaveyM69 wrote:

              2. Should that be @"nopersoneli" ?

              it seems hes trying to execute a SQL Stored Procedure using SqlCommand... see my reply

              Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

              D Offline
              D Offline
              DaveyM69
              wrote on last edited by
              #6

              Yeah - just saw the 'crapiness' of the question and jumped on the obvious without too much thought. I never even looked at the beginning of the statement - the possibilities I spotted from briefly scanning just one line of code made me close my eyes!

              Dave
              BTW, in software, hope and pray is not a viable strategy. (Luc Pattyn)
              Expect everything to be hard and then enjoy the things that come easy. (code-frog)

              1 Reply Last reply
              0
              • L leppie

                Harvey Saayman wrote:

                by the looks of things you need to do this...

                His code 'structure' is actually correctly and will do the same as both your examples. Note: the Add method returns a IDBParameter.

                xacc.ide - now with TabsToSpaces support
                IronScheme - 1.0 alpha 4a out now (29 May 2008)
                ((lambda (x) `((lambda (x) ,x) ',x)) '`((lambda (x) ,x) ',x))

                H Offline
                H Offline
                Harvey Saayman
                wrote on last edited by
                #7

                leppie wrote:

                is actually correctly

                [joke] Don't let Dalek Dave see that, you'll definitively get a English lesson ;P [/joke]

                leppie wrote:

                the Add method returns a IDBParameter.

                I didn't even notice that! The examples i gave is how i use the SqlCommand(or used, im a Linq fan boy now!), the latter of the two is used for DateTime parameters to ensure that the data gets to the db in the correct format.

                Harvey Saayman - South Africa Junior Developer .Net, C#, SQL you.suck = (you.Passion != Programming & you.Occupation == jobTitles.Programmer) 1000100 1101111 1100101 1110011 100000 1110100 1101000 1101001 1110011 100000 1101101 1100101 1100001 1101110 100000 1101001 1101101 100000 1100001 100000 1100111 1100101 1100101 1101011 111111

                1 Reply Last reply
                0
                • N NiloofarNoroozi

                  hi when i run this code this generate error why? objCommand.Parameters.Add("@nopersoneli", SqlDbType.int).Value =int.parse(txtNoPersoneli.text); thanks a lot

                  N Offline
                  N Offline
                  nelsonpaixao
                  wrote on last edited by
                  #8

                  objCommand.Parameters.Add("@nopersoneli", SqlDbType.int).Value =
                  convert.Toint32(txtNoPersoneli.text);

                  if that doesn´t work is because "txtNoPersoneli.text" cannot be converted to a int value, or "@nopersoneli" is not int. listen, there is not a reason for that not work :-O

                  nelsonpaixao@yahoo.com.br trying to help & get help

                  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