Microsoft Enterprises Library provide API where we dont need to open and close connection and they have sme predefind method .You dont need to create your own method .it has pedefined method for all that things for insert update delete retrieve and some more specific operation...........
You have to download the Entterprise lIbrary first and Add some Dll through AddReferences from a bin folder of Enterprises Library add
using Microsoft.Practices.EnterpriseLibrary.Data.dll
using Microsoft.Practices.EnterpriseLibrary.Common..dll
and Add the classes in code behind
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
using Microsoft.Practices.EnterpriseLibrary.Data.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Data;
//Retrieve and Insert value Using Entrprises library
protected void Page_Load(object sender, EventArgs e)
{
Database db = DatabaseFactory.CreateDatabase();
string sqlcommand = "select * from emp";
System.Data.Common.DbCommand dbCommand = db.GetSqlStringCommand(sqlcommand);
using (IDataReader reader = db.ExecuteReader(
dbCommand))
{
Gridview1.DataSource = reader;
Gridview1.DataBind();
}
}
public void save(string name)
{
DatabaseFactory.CreateDatabase().ExecuteNonQuery("inserts12",name);
}
protected void Button1_Click(object sender, EventArgs e)
{
save("subhash");
}
/////////web.config file
inside the ConfigSection
section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings,Microsoft.Practices.EnterpriseLibrary.Data" />
after closing configsection You have to add
/configSections>
dataConfiguration defaultDatabase="Master1"/>
//dataconfiguration same name as the connection string because DatabaseFactory.CreateDatabase(); using for connection
//connection string
add name="Master1" providerName="System.Data.SqlClient" connectionString="Data Source=subhash-9f7eec2;user id=;password=;database=Master;integrated security=sspi;"/>
Tuesday, March 22, 2011
Subscribe to:
Posts (Atom)