Writing to an ms access database using C# Window Application

Please try below code to write in MS ACCESS databse using C# Window Application:

System.Data.OleDb.OleDbConnection conn = new System.Data.OleDb.OleDbConnection(@"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=C:\Users\amar\Documents\Database1.accdb");
conn.Open();
using (System.Data.OleDb.OleDbCommand cmd = new System.Data.OleDb.OleDbCommand())
{
     cmd.Connection = conn;
     cmd.CommandText = "Insert Into Employee (UserName, fname, sname, email) values ('amar','Amar Prakash','Jaiswal','[email protected]')";
     cmd.ExecuteNonQuery();
}
conn.Close();
This entry was posted in General and tagged , , . Bookmark the permalink.

3 Responses to Writing to an ms access database using C# Window Application

  1. JhamanDas says:

    how to insert values using text box???

  2. admin says:

    For string type
    ‘” + txtName.Text + “‘
    and for int type/float type/decimal type
    ” + txtAge.Text + ”

    so in values section of insert command replace hard-coded value as below

    values (‘” + txtFName.Text + “‘ ,'” + txtFullName.Text + “‘ ,'” + txtLName.Text + “‘ ,'” + txtEmail.Text + “‘ )

Leave a Reply to JhamanDas Cancel reply

Your email address will not be published. Required fields are marked *