HOW to READ and WRITE to MS ACCESS using C#.net

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prabur
    New Member
    • Feb 2008
    • 3

    HOW to READ and WRITE to MS ACCESS using C#.net

    hi
    i need to store the value which i entered in a textbox to the MS ACCESS file(ie . .mdb file).. and hw can i retrive the data from MS ACCESS....
  • todashah
    New Member
    • Feb 2008
    • 26

    #2
    First use System.Data.Ole Db name space. Write the following code
    in button click event.
    string myConnectionStr ing="";
    myConnectionStr ing = "Provider =Microsoft.Jet. OLEDB.4.0; Data Source=D:\\pers on.mdb";
    OleDbConnection myConnection = new OleDbConnection (myConnectionSt ring);
    string myInsertQuery=" INSERT INTO emp Values('"+ textBox1.Text "')";
    OleDbCommand myCommand =new OleDbCommand (myInsertQuery) ;
    myCommand.Conne ction = myConnection;

    myConnection.Op en ();
    try
    {
    myCommand.Execu teNonQuery ();
    MessageBox.Show ("records are successfully insert");
    }
    catch(Exception ex)
    {
    MessageBox.Show (ex.Message.ToS tring ());
    }
    myConnection.Cl ose ();


    Kindly Note that here i assume that we have created person.mdb file in D drive & there is a emp table in this file.

    Originally posted by prabur
    hi
    i need to store the value which i entered in a textbox to the MS ACCESS file(ie . .mdb file).. and hw can i retrive the data from MS ACCESS....

    Comment

    Working...