I am trying to create a "simple" c# windows application for adding data from textboxes to a MS Access database on the local machine. I am new to C# and have not found a good tutorial on how to do this. I have viewed multiple sites and this is my first go at it. I am recieving a "syntax error in the INSERT INTO statement" message during debug.
Help would be appreciated. Sorry about formatting issues if it does not post correctly(first evolution).
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.OleDb;
namespace FirearemsSerial
{
public partial class Firearms : Form
{
public Firearms()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
}
private void addnewButton_Click(object sender, EventArgs e)
{
string SERIAL = serialTextbox.Text;
string MANU = manuTextbox.Text;
string MODEL = modelTextbox.Text;
string CALIBER = caliberTextbox.Text;
string VALUE = valueTextbox.Text;
string DESCRIP = descripTextbox.Text;
{
OleDbConnection conn = new OleDbConnection(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Documents and Settings\AyJack\My Documents\FirearmsS.mdb");
OleDbCommand cmmd = new OleDbCommand("INSERT INTO Firearm (SERIAL, MANU, MODEL, CALIBER, VALUE, DESCRIP) " + "VALUES (@SERIAL, @MANU, @MODEL, @CALIBER, @VALUE,@DESCRIP)", conn);
cmmd.Parameters.Add("@SERIAL", OleDbType.VarChar).Value = SERIAL;
cmmd.Parameters.Add("@MANU", OleDbType.VarChar).Value = MANU;
cmmd.Parameters.Add("@MODEL", OleDbType.VarChar).Value = MODEL;
cmmd.Parameters.Add("@CALIBER", OleDbType.VarChar).Value = CALIBER;
cmmd.Parameters.Add("@VALUE", OleDbType.VarChar).Value = VALUE;
cmmd.Parameters.Add("@DESCRIP", OleDbType.VarChar).Value = DESCRIP;
conn.Open();
cmmd.ExecuteNonQuery();
conn.Close();
MessageBox.Show("Record Added");
}
}
private void clearButton_Click(object sender, EventArgs e)
{
serialTextbox.Text = "";
manuTextbox.Text = "";
modelTextbox.Text = "";
caliberTextbox.Text = "";
valueTextbox.Text = "";
descripTextbox.Text = "";
}
private void exitButton_Click(object sender, EventArgs e)
{
this.Close();
}
}
}
`