I get this error when i try to run my code
System.Data.SqlClient.SqlException: 'Incorrect syntax near '00'.'
I can't figure out the syntax error
using System;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Windows.Forms;
namespace Barcode_Scanning
{
public partial class AddForm : Form
{
SqlCommand cmd;
SqlConnection con;
SqlDataAdapter da;
public AddForm()
{
InitializeComponent();
}
private void btnBack_Click(object sender, EventArgs e)
{
FormHandler.EditForm.Show();
Hide();
}
protected override void OnClosed(EventArgs e)
{
Application.Exit();
base.OnClosed(e);
}
private void btnAdd_Click(object sender, EventArgs e)
{
int quantity;
int price;
int barcodes;
string name;
DateTime date;
name = tbxName.Text;
date = Convert.ToDateTime(tbxDate.Text);
barcodes = Convert.ToInt32(tbxBarcode.Text);
quantity = Convert.ToInt32(tbxQuantity.Text);
price = Convert.ToInt32(tbxPrice.Text);
con = new SqlConnection("Data Source = (LocalDB)\\MSSQLLocalDB; AttachDbFilename = \"C:\\Users\\hannes.corbett\\Desktop\\Barcode Scanning\\Barcode Scanning\\BarcodeDB.mdf\"; Integrated Security = True");
con.Open();
cmd = new SqlCommand("INSERT INTO Products (Barcodes, Name, EDate, Quantity, Price) VALUES (" + barcodes + "," + name + "," + date + "," + quantity + "," + price + ")", con);
cmd.ExecuteNonQuery();
con.Close();
tbxBarcode.Text = String.Empty;
tbxName.Text = String.Empty;
tbxDate.Text = String.Empty;
tbxQuantity.Text = String.Empty;
tbxPrice.Text = String.Empty;
}
}
}
I'm new to C# and to stackoverflow so forgive me for bad structure in my post :) Any tips on how to better my code would be very much appreciated! Thanks beforehand