i am trying to insert data from a form to msaccess database i have the current code
OleDbConnection con = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
con.ConnectionString = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Users\kunz\Documents\Visual Studio 2010\WebSites\Assignment_2_Mark_2\App_Data\nuclearpopsicledb.mdb";
cmd.Connection = con;
string sql = "insert into users values('"+tbUname.Text+"','"+tbPass.Text+"','"+tbName.Text+"','"+tbEmail.Text+"','"+tbEmail.Text+"')";
try
{
con.Open();
cmd.CommandText = sql;
cmd.ExecuteNonQuery();
con.Close();
Label1.Text = "TRY";
}
catch(Exception ex)
{
Label1.Text = ex.ToString();
con.Close();
}
my data base is structured like:
|username | password | name | email |
but when ever i run it i get an error like
System.Data.OleDb.OleDbException: Number of query values and destination fields are not the same. at System.Data.
i am not sure what i am doing wrong i am a beginner in C#
OleDbConnectionare not being handled properly. Wrap them in a using statement.