I am having issues writing new data from my form to my access (mdb). I have a form with a few fields that work fine, I can read the data in the table. However, I can't edit in the form and write back new info into the database? See code below and if possible please edit a solution. I have exhausted all options at this point. I am also new to C#, so I apologize in advance for not explaining everything correctly!
public Form1()
{
InitializeComponent();
}
private void WObutton_Click(object sender, EventArgs e)
{
OleDbConnection conn = new OleDbConnection();
conn.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\Michael\Documents\Visual Studio 2012\Projects\WorkOrderTKv2\WorkOrderTKv2TestAccessdb.mdb";
conn.Open();
OleDbCommand cmmd = new OleDbCommand("INSERT INTO TestFC (TestFC) Values(@Name)", conn);
if (conn.State == ConnectionState.Open)
{
cmmd.Parameters.Add("@Name", OleDbType.VarWChar, 20).Value = Name;
try
{
cmmd.ExecuteNonQuery();
MessageBox.Show("DATA ADDED");
conn.Close();
}
catch (OleDbException expe)
{
MessageBox.Show(expe.Message);
conn.Close();
}
}
else
{
MessageBox.Show("CON FAILED");
}
}