SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
12,484 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Hi I have a sql query syntax error near 150.00 the error states If someone could have the time to help me fix it please.
private void AddPayment_Button_Click(object sender, EventArgs e)
{
string insertQuery = "INSERT INTO Debt_Payment_Tracker.payments(payments_id,payments_amount,payments_date,payments_total)VALUES('"+recNum+ "," + Convert.ToDouble(valuePicker_CB.SelectedItem) + "," + dateUS + "," + 150.00;"'));
MySqlCommand comand = new MySqlCommand(insertQuery, Connection);
try
{
if (comand.ExecuteNonQuery() == 1)
{
MessageBox.Show("Data Inserted");
}
else
{
MessageBox.Show("Data Not Inserted !");
}
Connection.Close();
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
throw;
}
Debt_Payment_Tracker.payments;";
}
This should work:
string insertQuery = "INSERT INTO Debt_Payment_Tracker.payments(payments_id,payments_amount,payments_date,payments_total) VALUES (@payments_id, @payments_amount, @payments_date, @payments_total);";
MySqlCommand comand = new MySqlCommand(insertQuery, Connection);
command.Parameters.AddWithValue("@payments_id", recNum);
command.Parameters.AddWithValue("@payments_amount", Convert.ToDouble(valuePicker_CB.SelectedItem));
command.Parameters.AddWithValue("@payments_date", dateUS);
command.Parameters.AddWithValue("@payments_total", 150.00);
try {
if (comand.ExecuteNonQuery() == 1) {
MessageBox.Show("Data Inserted");
} else {
MessageBox.Show("Data Not Inserted !");
}
Connection.Close();
} catch (Exception ex) {
MessageBox.Show(ex.Message);
throw;
}
You had this on the last line and it looks like a fragment of another query - I'd remove it because it'll cause a C# syntax error:
Debt_Payment_Tracker.payments;";