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 8936401
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T10:12:28+00:00 2026-06-15T10:12:28+00:00

I am confused by the following issue; I have a C# (WindowsForms) application which

  • 0

I am confused by the following issue;

I have a C# (WindowsForms) application which I connect to a SQL Server DB and have no problem to INSERT, SELECT, UPDATE… until I started to work with numerical data;

Purpose of this application is to manage employees, their contracts, rate of work, contracts durations, hourly rates… and do some funny calculations with that, nothing magic.

Basically, I need to store some values (decimal? double? float?) with the format “0000,0000” in my DB.

  • In my DB, I have set my table with all columns where I require these “000,0000” values to decimal

  • In my forms, I haven’t specified any specific properties to my textboxes,

  • To insert I use a method for which I defined decimal arguments

        public void createNewContract(int employeeId, string agency, string role, string contractType, string startDate,
        string endDate, string lineManager, string reportTo, string costCenter, string functionEng, string atrNo, string atrDate, string prNo, string prDate,
        string poNo, string poDate, string comments, decimal duration, decimal workRatePercent, string currency, decimal hourlyRate, decimal value)
    {
        if (conn.State.ToString() == "Closed")
        {
            conn.Open();
        }
        SqlCommand newCmd = conn.CreateCommand();
        newCmd.Connection = conn;
        newCmd.CommandType = CommandType.Text;
        newCmd.CommandText = "INSERT INTO tblContracts (CreatedById, CreationDate, EmployeeId, Role, ContractType, StartDate, "
        + "EndDate, Agency, LineManager, ReportTo, CostCenter, FunctionEng, AtrNo, AtrDate, PrNo, PrDate, PoNo, PoDate, Comments, Duration, WorkRatePercent, Currency, HourlyRate, Value)"
        + "VALUES ('" + connectedUser.getUserId() + "','" + DateTime.Now.ToString("dd/MM/yyyy hh:mm:ss") + "','" + employeeId + "','" + role + "','" + contractType
        + "','" + startDate + "','" + endDate + "','" + agency + "','" + lineManager + "','" + reportTo + "','" + costCenter + "','" + functionEng + "','" + atrNo + "','" + atrDate + "','" + prNo
         + "','" + prDate + "','" + poNo + "','" + poDate + "','" + comments + "','" + duration + "','" + workRatePercent + "','" + currency + "','" + hourlyRate + "','" + value + "')";
        newCmd.ExecuteNonQuery();
        MessageBox.Show("Contract has been successfully created", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    

(through this method, I only need to insert as 00,0000 a duration (nb hours), workrate percentage, an hourly rate (money in a currency) and a value (money in a currency))

  • To capture my textboxes values and send them through my method ‘createNewContrat’, I have tried
    Convert.ToDecimal(this.txtDuration.Text) and plenty other things that seemed good to me, but i don’t manage to understand the mechanic and i’m certainly not using the most pratical/clever solution…

I keep getting the following error;

System.FormatException: Le format de la chaîne d’entrée est incorrect. = The format of the input/entry string is incorrect
à System.Number.StringToNumber(String str, NumberStyles options, NumberBuffer& number, NumberFormatInfo info, Boolean parseDecimal)
à System.Number.ParseDecimal(String value, NumberStyles options, NumberFormatInfo numfmt)
à System.Convert.ToDecimal(String value)

What would you recommend?

  • 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-06-15T10:12:29+00:00Added an answer on June 15, 2026 at 10:12 am

    First of all, Always use using when dealing with SqlConnection and SqlCommand and all other classes that implements IDisposable just read more about it..

    Second thing, Always use parameters with SqlCommand and never pass the values as a string to the sql string. This is a serious security issue. In addition to that parameters makes your code human friendly!

    // Always use (using) when dealing with Sql Connections and Commands
    using (sqlConnection conn = new SqlConnection())
    {
        conn.Open();
    
        using (SqlCommand newCmd = new SqlCommand(conn))
        {
            newCmd.CommandType = CommandType.Text;
    
            newCmd.CommandText = 
                  @"INSERT INTO tblContracts (CreatedById, CreationDate, EmployeeId, Role, ContractType, StartDate, EndDate, Agency, LineManager, ReportTo, CostCenter, FunctionEng, AtrNo, AtrDate, PrNo, PrDate, PoNo, PoDate, Comments, Duration, WorkRatePercent, Currency, HourlyRate, Value) 
                  VALUES (@UserID, @CreationDate, @EmployeeID, @Role.....etc)";
    
            // for security reasons (Sql Injection attacks) always use parameters
            newCmd.Parameters.Add("@UserID", SqlDbType.NVarChar, 50)
                 .Value = connectedUser.getUserId();
    
            newCmd.Parameters.Add("@CreationDate", SqlDbType.DateTime)
                 .Value = DateTime.Now;
    
            // To add a decimal value from TextBox
            newCmd.Parameters.Add("@SomeValue", SqlDbType.Decimal)
                 .Value = System.Convert.ToDecimal(txtValueTextBox.Text);
    
            // complete the rest of the parameters
            // ........
    
            newCmd.ExecuteNonQuery();
    
            MessageBox.Show("Contract has been successfully created", "Completed", MessageBoxButtons.OK, MessageBoxIcon.Information);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am little bit confused about following problem & their solutions: i have 2
hello i have just start using Raphael but i'm very confused in the following
I have set up a remote server running SQl Server Web edition and full
I have WinForm application which is almost ready to go for production and here
I have a really weird issue with Sql queries on unicode data. Here's what
I have the following table which I'll call 'example' id name last_name 01 Adam
I have the following model in my mvc3 application. I want to have two
We are seeing a problem with our company's application that has me very confused
I have the following line of code in my program which I took from
I have a newsletter application where a newsletter has multiple articles within each issue.

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.