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. Web Development
  3. ASP.NET
  4. (Input string was not in a correct format) with ExecuteReader

(Input string was not in a correct format) with ExecuteReader

Scheduled Pinned Locked Moved ASP.NET
sharepointdatabasehelpquestion
7 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.
  • J Offline
    J Offline
    Jassim Rahma
    wrote on last edited by
    #1

    I am getting Input string was not in a correct format with the following code:

    sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
    sql_connection.Open();

    sql_command = new MySqlCommand("sp_check_if_member_exist", sql_connection);
    sql_command.CommandType = CommandType.StoredProcedure;
    sql_command.Parameters.AddWithValue("param_member_id", MySqlDbType.Int32).Value = Convert.ToInt32(Request.QueryString["id"]);
    sql_command.Parameters.AddWithValue("param_member_guid", MySqlDbType.VarChar).Value = Convert.ToString(Request.QueryString["guid"]);
    sql_command.Parameters.Add("param_is_exist", MySqlDbType.Bit).Direction = ParameterDirection.Output;

    sql_reader = sql_command.ExecuteReader();
    sql_reader.Read();

    if (sql_reader.HasRows)
    {
    if (Convert.ToBoolean(sql_command.Parameters["param_is_exist"].Value) == true)
    {
    // prompt for activation;
    panelMessage.Visible = false;
    panelActivation.Visible = true;
    }
    else
    {
    panelActivation.Visible = false;
    lblMessage.Text = "Error activating your membership!";
    panelMessage.Visible = true;
    return;
    }

    The error occurs on this line:

    sql_reader = sql_command.ExecuteReader();

    where is my mistake?

    L P S 4 Replies Last reply
    0
    • J Jassim Rahma

      I am getting Input string was not in a correct format with the following code:

      sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
      sql_connection.Open();

      sql_command = new MySqlCommand("sp_check_if_member_exist", sql_connection);
      sql_command.CommandType = CommandType.StoredProcedure;
      sql_command.Parameters.AddWithValue("param_member_id", MySqlDbType.Int32).Value = Convert.ToInt32(Request.QueryString["id"]);
      sql_command.Parameters.AddWithValue("param_member_guid", MySqlDbType.VarChar).Value = Convert.ToString(Request.QueryString["guid"]);
      sql_command.Parameters.Add("param_is_exist", MySqlDbType.Bit).Direction = ParameterDirection.Output;

      sql_reader = sql_command.ExecuteReader();
      sql_reader.Read();

      if (sql_reader.HasRows)
      {
      if (Convert.ToBoolean(sql_command.Parameters["param_is_exist"].Value) == true)
      {
      // prompt for activation;
      panelMessage.Visible = false;
      panelActivation.Visible = true;
      }
      else
      {
      panelActivation.Visible = false;
      lblMessage.Text = "Error activating your membership!";
      panelMessage.Visible = true;
      return;
      }

      The error occurs on this line:

      sql_reader = sql_command.ExecuteReader();

      where is my mistake?

      L Offline
      L Offline
      Lost User
      wrote on last edited by
      #2

      There are three suggestion and I think it supposed to be one of them: 1. Check you are entering correct store procedure name 2. Check you are entering correct parameters names 2. Check you are entering correct parameters values

      Meysam

      1 Reply Last reply
      0
      • J Jassim Rahma

        I am getting Input string was not in a correct format with the following code:

        sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
        sql_connection.Open();

        sql_command = new MySqlCommand("sp_check_if_member_exist", sql_connection);
        sql_command.CommandType = CommandType.StoredProcedure;
        sql_command.Parameters.AddWithValue("param_member_id", MySqlDbType.Int32).Value = Convert.ToInt32(Request.QueryString["id"]);
        sql_command.Parameters.AddWithValue("param_member_guid", MySqlDbType.VarChar).Value = Convert.ToString(Request.QueryString["guid"]);
        sql_command.Parameters.Add("param_is_exist", MySqlDbType.Bit).Direction = ParameterDirection.Output;

        sql_reader = sql_command.ExecuteReader();
        sql_reader.Read();

        if (sql_reader.HasRows)
        {
        if (Convert.ToBoolean(sql_command.Parameters["param_is_exist"].Value) == true)
        {
        // prompt for activation;
        panelMessage.Visible = false;
        panelActivation.Visible = true;
        }
        else
        {
        panelActivation.Visible = false;
        lblMessage.Text = "Error activating your membership!";
        panelMessage.Visible = true;
        return;
        }

        The error occurs on this line:

        sql_reader = sql_command.ExecuteReader();

        where is my mistake?

        P Offline
        P Offline
        Parthi Bun
        wrote on last edited by
        #3

        check d database.... used text field values are should not be empty..........

        1 Reply Last reply
        0
        • J Jassim Rahma

          I am getting Input string was not in a correct format with the following code:

          sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
          sql_connection.Open();

          sql_command = new MySqlCommand("sp_check_if_member_exist", sql_connection);
          sql_command.CommandType = CommandType.StoredProcedure;
          sql_command.Parameters.AddWithValue("param_member_id", MySqlDbType.Int32).Value = Convert.ToInt32(Request.QueryString["id"]);
          sql_command.Parameters.AddWithValue("param_member_guid", MySqlDbType.VarChar).Value = Convert.ToString(Request.QueryString["guid"]);
          sql_command.Parameters.Add("param_is_exist", MySqlDbType.Bit).Direction = ParameterDirection.Output;

          sql_reader = sql_command.ExecuteReader();
          sql_reader.Read();

          if (sql_reader.HasRows)
          {
          if (Convert.ToBoolean(sql_command.Parameters["param_is_exist"].Value) == true)
          {
          // prompt for activation;
          panelMessage.Visible = false;
          panelActivation.Visible = true;
          }
          else
          {
          panelActivation.Visible = false;
          lblMessage.Text = "Error activating your membership!";
          panelMessage.Visible = true;
          return;
          }

          The error occurs on this line:

          sql_reader = sql_command.ExecuteReader();

          where is my mistake?

          S Offline
          S Offline
          StianSandberg
          wrote on last edited by
          #4

          SqlCommand.Parameters.AddWithValue() does not take datatype as an parameter. You should add the parameter name and value (not datatype)

          sql_command.Parameters.AddWithValue("param_member_id", Request.QueryString["id"]);

          http://derekreynolds.wordpress.com/2011/05/16/using-sqlcommand-and-addwithvalue-parameters-to-execute-sql-insert/[^] But your error "Input string was not in a correct format" is because some convert's did not succeed. When converting strings-->int etc you should use TryParse

          private static void TryToParse(string value)
          {
          int number;
          bool result = Int32.TryParse(value, out number);
          if (result)
          {
          Console.WriteLine("Converted '{0}' to {1}.", value, number);
          }
          else
          {
          if (value == null) value = "";
          Console.WriteLine("Attempted conversion of '{0}' failed.", value);
          }
          }

          -------------------- When Chuck Norris' dreams come true, your worst nightmares begin.

          J 1 Reply Last reply
          0
          • S StianSandberg

            SqlCommand.Parameters.AddWithValue() does not take datatype as an parameter. You should add the parameter name and value (not datatype)

            sql_command.Parameters.AddWithValue("param_member_id", Request.QueryString["id"]);

            http://derekreynolds.wordpress.com/2011/05/16/using-sqlcommand-and-addwithvalue-parameters-to-execute-sql-insert/[^] But your error "Input string was not in a correct format" is because some convert's did not succeed. When converting strings-->int etc you should use TryParse

            private static void TryToParse(string value)
            {
            int number;
            bool result = Int32.TryParse(value, out number);
            if (result)
            {
            Console.WriteLine("Converted '{0}' to {1}.", value, number);
            }
            else
            {
            if (value == null) value = "";
            Console.WriteLine("Attempted conversion of '{0}' failed.", value);
            }
            }

            -------------------- When Chuck Norris' dreams come true, your worst nightmares begin.

            J Offline
            J Offline
            Jassim Rahma
            wrote on last edited by
            #5

            why converting problem? I only have two paramaters: param_member_id which is int and it's int in MySQL. param_member_guid which is varchar and it's varchar in MySQL here is my values when getting error:

            id=66&guid=9abc9f1e-e2f3-11e1-b39f-00ffceb1d3b5}

            J 1 Reply Last reply
            0
            • J Jassim Rahma

              why converting problem? I only have two paramaters: param_member_id which is int and it's int in MySQL. param_member_guid which is varchar and it's varchar in MySQL here is my values when getting error:

              id=66&guid=9abc9f1e-e2f3-11e1-b39f-00ffceb1d3b5}

              J Offline
              J Offline
              Jassim Rahma
              wrote on last edited by
              #6

              pleassssse.....

              1 Reply Last reply
              0
              • J Jassim Rahma

                I am getting Input string was not in a correct format with the following code:

                sql_connection = new MySqlConnection(ConfigurationManager.ConnectionStrings["SQLdb"].ConnectionString);
                sql_connection.Open();

                sql_command = new MySqlCommand("sp_check_if_member_exist", sql_connection);
                sql_command.CommandType = CommandType.StoredProcedure;
                sql_command.Parameters.AddWithValue("param_member_id", MySqlDbType.Int32).Value = Convert.ToInt32(Request.QueryString["id"]);
                sql_command.Parameters.AddWithValue("param_member_guid", MySqlDbType.VarChar).Value = Convert.ToString(Request.QueryString["guid"]);
                sql_command.Parameters.Add("param_is_exist", MySqlDbType.Bit).Direction = ParameterDirection.Output;

                sql_reader = sql_command.ExecuteReader();
                sql_reader.Read();

                if (sql_reader.HasRows)
                {
                if (Convert.ToBoolean(sql_command.Parameters["param_is_exist"].Value) == true)
                {
                // prompt for activation;
                panelMessage.Visible = false;
                panelActivation.Visible = true;
                }
                else
                {
                panelActivation.Visible = false;
                lblMessage.Text = "Error activating your membership!";
                panelMessage.Visible = true;
                return;
                }

                The error occurs on this line:

                sql_reader = sql_command.ExecuteReader();

                where is my mistake?

                L Offline
                L Offline
                Lost User
                wrote on last edited by
                #7

                I think I have already answered this question in a different forum. Anyway, here is your problem In this line:

                sql_command.Parameters.AddWithValue("param_member_id", MySqlDbType.Int32).Value = Convert.ToInt32(Request.QueryString["id"]);

                and the next two lines, you're actually passing Data Types (MySqlDbType.Int32) instead of the actual value. The AddWithValue() method expects the actual value rather than the data type. So do something like :

                sql_command.Parameters.AddWithValue("param_member_id", Convert.ToInt32(Request.QueryString["id"]));

                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