In this article i will tell you How to insert record into access database using C#.Net.
In the Previous articles i explained how to get connection string from web .config file, how to create dynamic xml sitemap in asp.net, How to solve password length minimum 7 non alphanumeric characters required 1, How to apply pagination in repeater control using asp.net, How to add my website to google, How to create connection string and many more about C#.Net.
Use below namespace.
Write below code on click event of the button.
OleDbConnection con = new OleDbConnection("YourConnectionString");
OleDbCommand cmd = new OleDbCommand("insert into table1(name,age,class)values('Harish Sharma','22','B.A Part 1')", con);
lbl_msg.Text = "Record inserted successfully.";
lbl_msg.Text ="Error Occured.";
Below is the explanation.
Create connection with your database. Replace "YourConnectionString" with your own connection string.
Open Your Connection.
Create Sql command for inserting records. Here i am inserting the records into columns "name","age","class"of table "table1". Also pass your connection in oledbcommand.
Show Message if record inserted successfully.
Close the connection.