write below code in your web config file
<add name="AccessConnectionString" connectionString="Provider=
Microsoft.ACE.OLEDB.12.0;Data Source=G:\Working Project\StickerC\App_Data\ Database1.accdb;Persist Security Info=False;Jet OLEDB:Database Password=;" providerName="System.Data. OleDb" />
<add name="AccessConnectionString" connectionString="Provider=
this is for insert the data in DataBase.
please do not forget to add the name sapce using System.Data.OleDb
public void InsertData()
{
//Establish the coneection
OleDbConnection myDataConnection = new OleDbConnection( ConfigurationManager. ConnectionStrings[" AccessConnectionString"]. ConnectionString);
// open the data connection.
myDataConnection.Open();
OleDbCommand cmd = myDataConnection. CreateCommand();
cmd.CommandText = "Insert into tbldata (typeId,data) values (3,'rohit')";
cmd.ExecuteNonQuery();
// display the connection's current state open/closed.
//Response.Write(string. Format("<i><b>Connection state:</b> {0}</i><br />", myDataConnection.State));
// close the data connection.
myDataConnection.Close();
// again display the connection's current state open/closed.
// Response.Write(string.Format(" <i><b>Connection state:</b> {0}</i>", myDataConnection.State));
// dispose the connection object to release the resources.
myDataConnection.Dispose();
}
This comment has been removed by a blog administrator.
ReplyDelete