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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T23:08:06+00:00 2026-06-04T23:08:06+00:00

The program is with C# WinForms and SQL Server 2008. When I want to

  • 0

The program is with C# WinForms and SQL Server 2008. When I want to enter data that includes the value from a DateTimePicker I can see that the wording is in Dutch and then I get an error about converting of the value. Is there any way to pre-program it to get around this? I’ve caught the error and here it is.

error

        try
        {
            SqlConnection connect = new SqlConnection("Data Source=Localhost\\SQLExpress;Initial Catalog=DataBase;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();

            /******************** Inserting ********************/
            string query = "INSERT INTO spending VALUES (";
            query += "'" + date_dateTimePicker.Value + "', "; // Date
            query += "'" + Convert.ToDecimal(amount_spent_textBox.Text) + "', "; // Amount spent
            query += "'" + spent_on_textBox.Text + "')"; // Spent on
            connect.Open();
            da.InsertCommand = new SqlCommand(query, connect);
            da.InsertCommand.ExecuteNonQuery();

            connect.Close();
        }

        catch (Exception error)
        {
            MessageBox.Show(error.ToString());
        }

Things are getting thick.. I got this error while trying to insert a dateTimePicker value into the database the same way I did with the code above. It worked perfectly fine on my computer but it won’t work here. Can someone explain? Here is the error:

error

Code used:

string update = "UPDATE table SET the_date = '" + the_date_dateTimePicker.Value + "' WHERE instance_ID = 1";
        connect.Open();
        da.InsertCommand = new SqlCommand(update, connect);
        da.InsertCommand.ExecuteNonQuery();
        connect.Close();

Ok here is the full code for the form I am working on now, the one that shows this error. Most of the forms are structured like this so if I get this one right, there shouldn’t be any problems with the rest of them. I’m testing this on my computer so if it works here it should work there also.

Take a look, I don’t know what to do anymore.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace TheNamespace
{
public partial class submit_spending : Form
{
    public submit_spending()
    {
        InitializeComponent();
    }

    private void submit_button_Click(object sender, EventArgs e)
    {
        try
        {
            SqlConnection connect = new SqlConnection("Data Source=Localhost\\SQLExpress;Initial Catalog=TheDataBase;Integrated Security=True");
            SqlDataAdapter da = new SqlDataAdapter();

            /******************** Inserting ********************/
            string query = "INSERT INTO spending VALUES (@date, @amount_spent, @spent_on)";
            SqlCommand command = new SqlCommand(query);
            command.Parameters.AddWithValue("date", date_dateTimePicker.Value);
            command.Parameters.AddWithValue("amount_spent", Convert.ToDecimal(amount_spent_textBox.Text));
            command.Parameters.AddWithValue("spent_on", spent_on_textBox.Text);

            connect.Open();
            da.InsertCommand = new SqlCommand(query, connect);
            da.InsertCommand.ExecuteNonQuery();
            connect.Close();

            if (MessageBox.Show("Submitted.", "Spending submitted", MessageBoxButtons.OK) == DialogResult.OK)
            {
                this.Close();
            }
        }
        catch (Exception error)
        {
            MessageBox.Show(error.ToString());
        }
    }

    private void cancel_button_Click(object sender, EventArgs e)
    {
        this.Close();
    }
}
}
  • 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-04T23:08:08+00:00Added an answer on June 4, 2026 at 11:08 pm

    You can probably use an explicit ToString with a culture-invariant format to make sure that this works in any locale. This is a bit of a hack, but replacing this line:

    command.Parameters.AddWithValue("date", date_dateTimePicker.Value);
    

    with this should work:

    command.Parameters.AddWithValue("date", date_dateTimePicker.Value.ToString("s"));
    

    This will give you an ISO 8601 formatted date-time string, which is an international standard with an unambiguous specification. Also, this format is not affected by the SET DATEFORMAT or SET LANGUAGE setting on your SQL Server instance.

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

Sidebar

Related Questions

I'm working against a SQL Server database that regularly has DateTime columns that can
In my C# winforms program I want to make an export function that will
I have a .NET winforms program that includes a feature to launch a specific
I have a simple updater program that copies files from a company server to
I'm working on converting a rather complex .NET WinForms program into a fully-integrated SQL
I have a winform program that uses Merge Replication to keep a local SQL
I'm writing a small winforms application that opens several instances of another program. To
C# - Winforms - SQL Server i am building an application which displays some
Scenario: 4 users launch separate instances of the same client program (Winforms) that is
Can a WinForms exe be installed to program files instead of the user profile

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.