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.

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:

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();
}
}
}
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:
with this should work:
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.