Hello Friends
To use the Microsoft .Net Enterprise Library you need to install Microsoft.Practices.EnterpriseLibrary.Data and Microsoft.Practices.EnterpriseLibrary.Common in GAC.
You will need to add the following to your web.config fileof Sharepoint Application:[It can be applied same for ASP.NET Application]
<configuration>
<configSections>
<section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.0.0.0, Culture=neutral, PublicKeyToken=1436591a4ef1d75a" />
</configSections>
<connectionStrings>
<add name="SQLConnenctionString" providerName="System.Data.SqlClient" connectionString="server=servername;database=dbname;Uid=username;Pwd=password;" />
</connectionStrings>
<dataConfiguration defaultDatabase="Databasename" />
Here is some of my sample code that makes database calls (sample code from microsoft is attached at bottom):
I have taken one Dropdownlist named as "ddlConcentrations" and binding data from database.
using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Data.Sql;
public class Testing
{
Database db = DatabaseFactory.CreateDatabase();
private void PopulateData(string Name)
{
DbCommand dbCommand = db.GetStoredProcCommand("SQLServerProcedurename");
db.AddInParameter(dbCommand, "@Name", DbType.String, Name);
ddlConcentrations.DataTextField = "Name";
ddlConcentrations.DataValueField = "Name";
ddlConcentrations.DataSource = db.ExecuteReader(dbCommand);
try
{
ddlConcentrations.DataBind();
}
catch (System.ArgumentOutOfRangeException e)
{
}
ddlConcentrations.Items.Insert(0, "");
}
}
Disha Shah
No comments:
Post a Comment