Hello ,
Some changes are required to connect with .sdf file .here i am using "Northwind" Database . first of all you have to modify you connectionstring in your web config file . you must mention what type of Provider you are using.
<add name="NorthwindConnectionString" connectionString="Data Source=|DataDirectory|\Northwind.sdf" providerName="Microsoft.SqlServerCe.Client.3.5" />
in the next stage ,
before you connecting to your database ,add this namespace.
using System.Data.SqlServerCe
because you are using Sql Compact edition .
Here , you have to use
SqlCeConnection ,SqlCeDataAdapter
instead of
sqlconnection,sqlcommand,and sqldatareade
to connect with database.
DataSet ds = new System.Data.DataSet();
void Bind()
{
SqlCeConnection con = new SqlCeConnection(ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString);
SqlCeDataAdapter da = new SqlCeDataAdapter("select p.[Product ID],p.[Product Name],c.[Category ID],c.[Category Name] from Products p inner join Categories c on p.[Category ID]=c.[Category ID]", con);
da.Fill(ds);
}
here you will get a collection of Products from "Northwind" database .
thanks