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. bit parameter problem

bit parameter problem

Scheduled Pinned Locked Moved C#
databasehelpcsharptutorialquestion
5 Posts 4 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.
  • M Offline
    M Offline
    Mr Kode
    wrote on last edited by
    #1

    i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks

    V T E 3 Replies Last reply
    0
    • M Mr Kode

      i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks

      V Offline
      V Offline
      Vasudevan Deepak Kumar
      wrote on last edited by
      #2

      What is the error that is thrown?

      Vasudevan Deepak Kumar Personal Homepage
      Tech Gossips
      All the world's a stage, And all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts... --William Shakespeare

      M 1 Reply Last reply
      0
      • V Vasudevan Deepak Kumar

        What is the error that is thrown?

        Vasudevan Deepak Kumar Personal Homepage
        Tech Gossips
        All the world's a stage, And all the men and women merely players. They have their exits and their entrances; And one man in his time plays many parts... --William Shakespeare

        M Offline
        M Offline
        Mr Kode
        wrote on last edited by
        #3

        can not convert from object to bool

        1 Reply Last reply
        0
        • M Mr Kode

          i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks

          T Offline
          T Offline
          telha
          wrote on last edited by
          #4

          Well I guess you can make a check like: bool myBool = comp.value==1?true:false

          Muhammad Talha

          1 Reply Last reply
          0
          • M Mr Kode

            i have stored procedure from SQL have bit parameter returns 1 or 0, the parameter works fine on SQL on C# i have problems, as the following: SqlCommand checkDone = new SqlCommand(); checkDone.Connection = con1; checkDone.CommandType = CommandType.Text; checkDone.CommandText = "checkCompatability"; SqlParameter complete = new SqlParameter("@award_num", SqlDbType.Int); complete.Direction = ParameterDirection.Output; complete.Value = int.Parse(comboAwardNum.Text); SqlParameter comp = new SqlParameter("@compatability", SqlDbType.Bit); comp.Direction = ParameterDirection.Output; bool mybool=bool.Parse(comp.Value).ToString();//error here lblresult.Text = comp.Value; checkDone.Parameters.Add(complete); checkDone.Parameters.Add(comp); checkDone.Connection.Open(); checkDone.ExecuteScalar(); checkDone.Connection.Close(); how to return parameter value from SQL? thanks

            E Offline
            E Offline
            Eslam Afifi
            wrote on last edited by
            #5

            Mr.Kode wrote:

            checkDone.CommandType = CommandType.Text;

            This should be checkDone.CommandType = CommandType.StoredProcedure; You're creating output parameters so they won't take input. You can make them InputOutput parameters to take values and then they can alter them.

            Mr.Kode wrote:

            bool mybool=bool.Parse(comp.Value).ToString();//error here

            This line of code has multiple errors. comp.Value is object and Parse takes a string parameter. comp.Value is object and has not been set. Another error in this line is that after you "parse" to bool, you're using ToString() and assigning it to bool :wtf: You retrieve values from the output parameters after the command has been executed. And it would be bool mybool = (bool)comp.Value; The same for the other SqlParameter.

            Mr.Kode wrote:

            checkDone.ExecuteScalar();

            Why ExecuteScalar? Use ExecuteNonQuery if you're not retrieving a value. And this question should have been asked in the SQL / ADO / ADO.NET forum :)

            Eslam Afifi

            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