none
mysql insert query RRS feed

  • Question

  • plz help me....

    am connecting vs2010 with Mysql6.0  .i wrote insert query like this.,

    MySqlConnection connection = new MySqlConnection(MyConnectionString);

                MySqlCommand cmd;
                connection.Open();
                 MessageBox.Show("connection established");
                try
                {
                    cmd = connection.CreateCommand();
                    cmd.CommandText = "insert into inventory(tag_id,category_id,product_id,product_name,gate_id,remarks)values(@tag_id,@category_id,@product_id,@product_name,@gate_id,@remarks)";
                    cmd.Parameters.AddWithValue("@tag_id",int.Parse( I_Tag.Text));
                    cmd.Parameters.AddWithValue("@category_id", int.Parse(I_Category.Text));
                    cmd.Parameters.AddWithValue("@product_id",int.Parse( I_Product.Text));
                    cmd.Parameters.AddWithValue("@product_name", I_ProName.Text);
                    cmd.Parameters.AddWithValue("@gate_id", int.Parse(I_Gate.Text));
                    cmd.Parameters.AddWithValue("@remarks", I_Remarks.Text);
                    cmd.ExecuteNonQuery();

                    MessageBox.Show("data inserted successfully");
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.StackTrace);
                }
                finally
                {
                    if (connection.State == ConnectionState.Open)
                    {
                        I_Tag.Text = "";
                        I_Category.Text = "";
                        I_Product.Text = "";
                        I_ProName.Text = "";
                        I_Gate.Text = "";
                        I_Remarks.Text = "";
                        connection.Close();
                    }
                }

    connection established properly. but the problem is: while inserting data into table ;am getting stacktrace as:

    at system.number.StringToNumber(.....)

    like some

    plz help me...............

    Saturday, October 19, 2013 11:31 AM

Answers

  • Check whether your string value (such as xxx.Text's value) can be converted to numeric.

    If still occurs, please remove try……catch……finally and directly debug your app by pressing F5 to tell us at which statement your exception is thrown out?


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    • Marked as answer by Eason_H Monday, October 28, 2013 1:23 AM
    Saturday, October 19, 2013 12:29 PM
  • Hi Rajeswari,

    Thanks for your posting.

    From your description, I know that you encounter some issue when you insert data into table, "system.number.StringToNumber(.....)"  is that System.FormatException. Based on my experience, I think that maybe there are two reason  :

    1) This could arise from invaild input.

    2)This could arise from a call to one of the Convert.ToIntxx functions ( viz.,ToInt16,ToInt32, ToInt64) or the Intxx.Parse()( Int16.Parse, Int32.Parse or Int64.parse) . The exception is not thrown for any value other than 0.

    This is due to corruption of a registry key's value that deals with globalization settings.

    The registry key "sPositiveSign" under HKEY_CURRENT_USER\Control Panel\International should be blank for this to work correctly.

    If this is set to 0 the above exception will occur. Change this value to " " in the registry key to correct this exception.

    Hope these help.


    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, October 22, 2013 6:05 AM
    Moderator

All replies

  • Check whether your string value (such as xxx.Text's value) can be converted to numeric.

    If still occurs, please remove try……catch……finally and directly debug your app by pressing F5 to tell us at which statement your exception is thrown out?


    Click For donating:Free Rice For the poor
    For spamming-sender issues, you can either report it at Microsoft Spamming Issue, or just find "Report Spam Here+Number" at Forum Issue;You can also find "Verify Your Account+Number" at "Forum Issue", where you can submit to be confirmed to paste links or images.
    For more things to talk about? StackOverFlow is your choice.

    • Marked as answer by Eason_H Monday, October 28, 2013 1:23 AM
    Saturday, October 19, 2013 12:29 PM
  • You are using int.Parse method to convert values, so you can check for the blank string. This method can't convert any blank string to number.

    Avik Das

    Saturday, October 19, 2013 2:00 PM
  • Hi Rajeswari,

    Thanks for your posting.

    From your description, I know that you encounter some issue when you insert data into table, "system.number.StringToNumber(.....)"  is that System.FormatException. Based on my experience, I think that maybe there are two reason  :

    1) This could arise from invaild input.

    2)This could arise from a call to one of the Convert.ToIntxx functions ( viz.,ToInt16,ToInt32, ToInt64) or the Intxx.Parse()( Int16.Parse, Int32.Parse or Int64.parse) . The exception is not thrown for any value other than 0.

    This is due to corruption of a registry key's value that deals with globalization settings.

    The registry key "sPositiveSign" under HKEY_CURRENT_USER\Control Panel\International should be blank for this to work correctly.

    If this is set to 0 the above exception will occur. Change this value to " " in the registry key to correct this exception.

    Hope these help.


    Lilia Gong <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.


    Tuesday, October 22, 2013 6:05 AM
    Moderator
  • Hi,

    1. You need to validate all the inputs you are passing as parameters. Input values that you are trying with Int.Parse should be numeric without blank spaces.

    2. And also the data type you are passing should match with MySql field data type.

    Tuesday, October 22, 2013 1:10 PM