Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6135027
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T17:25:46+00:00 2026-05-23T17:25:46+00:00

I’m new to creating applications using Visual Studio 2010 and MySQL. I am creating

  • 0

I’m new to creating applications using Visual Studio 2010 and MySQL. I am creating an application that adds the information to the database. But then when I click the add button, there is an error message which says Input string was not in a correct format. But I enter letters to the textbox and I used VarChar as the DataType. Now, I can’t figure out what’s the problem.

Code:

private void buttonaddcompany_Click(object sender, EventArgs e)
    {
        string MyConString = "SERVER=localhost;" + "DATABASE=payroll;" + "UID=root;" + "PASSWORD=admin;";
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        command.Connection = connection;
        using (MySqlConnection conn = new MySqlConnection(MyConString))
        {
            connection.Open();
            using (MySqlCommand com = connection.CreateCommand())
            {
                command.CommandText = "insert into company(company_name, company_other_names, company_office_number, company_office_building, company_office_street, company_office_village, company_municipality_name, company_municipality_zipcode, company_province_name, company_province_zipcode, company_country_name, company_country_zipcode) values(?company_name, ?company_other_names, ?company_office_number, ?company_office_building, ?company_office_street, ?company_office_village, ?company_municipality_name, ?company_municipality_zipcode, ?company_province_name, ?company_province_zipcode, ?company_country_name, ?company_country_zipcode)";
                command.Parameters.Add(new MySqlParameter("?company_name", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_other_names", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_office_number", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_office_building", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_office_street", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_office_village", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_municipality_name", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_municipality_zipcode", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_province_name", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_province_zipcode", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_country_name", MySqlDbType.VarChar));
                command.Parameters.Add(new MySqlParameter("?company_country_zipcode", MySqlDbType.VarChar));
                command.Parameters["?company_name"].Value = addcompname.Text;
                command.Parameters["?company_other_names"].Value = addcompothername.Text;
                command.Parameters["?company_office_number"].Value = addoffnumber.Text;
                command.Parameters["?company_office_building"].Value = addoffbuilding.Text;
                command.Parameters["?company_office_street"].Value = addoffstreet.Text;
                command.Parameters["?company_office_village"].Value = addoffvillage.Text;
                command.Parameters["?company_municipality_name"].Value = addoffmunname.Text;
                command.Parameters["?company_municipality_zipcode"].Value = addoffmunzipcode.Text;
                command.Parameters["?company_province_name"].Value = addoffprovname.Text;
                command.Parameters["?company_province_zipcode"].Value = addoffprovzipcode.Text;
                command.Parameters["?company_country_name"].Value = addoffcountryname.Text;
                command.Parameters["?company_country_zipcode"].Value = addoffcountryzipcode.Text;
                command.ExecuteNonQuery();
                MessageBox.Show("Data Saved");
            }
        }
    }

Screenshot:
screenshot of the FormatException

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-23T17:25:46+00:00Added an answer on May 23, 2026 at 5:25 pm

    Not an answer, but maybe a common way to fight such problems in a future. If I encounter such problems, I simplify it to minimal form. In your case this would be some thing like:

    private void buttonaddcompany_Click(object sender, EventArgs e)
    {
        string MyConString = "SERVER=localhost;" + "DATABASE=payroll;" + "UID=root;" + "PASSWORD=admin;";
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        command.Connection = connection;
        using (MySqlConnection conn = new MySqlConnection(MyConString))
        {
            connection.Open();
            using (MySqlCommand com = connection.CreateCommand())
            {
                command.CommandText = "insert into company(company_name, /* other fields here , */ company_country_zipcode) values(?company_name, 'company_other_names', /* other hardcoded fields here , */ 'company_country_zipcode')";
                command.Parameters.Add(new MySqlParameter("?company_name", SqlDbType.VarChar));
                command.Parameters["?company_name"].Value = addcompname.Text;
                command.ExecuteNonQuery();
                MessageBox.Show("Data Saved");
            }
        }
    }
    

    this allows to narrow places there some typos can drive you crazy. Stick with simplified form until problem is resolved, so you can be sure that code logic is correct. Then return to full code version and see if it working. If not, then probably it’s just typos.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I have a French site that I want to parse, but am running into
I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I want to count how many characters a certain string has in PHP, but
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.