samedi 5 juillet 2014

I want to change my all coding to ms access database


Vote count:

0




By mistake I used SQL tables and as well as written c sharp whole code, but the requirement is ms access database. Actually, my application is web store, according to category name to display their products. I used two tables: 1. Category 2. Product


Category table has been following fields.


CategoryID


CategoryName


Product table has been following fields.


PID


ImageName


ProductName


Price


CategoryID


I have stored procedure to get results according to category and their products.


ALTER PROCEDURE [dbo].[usp_GetProductsForCategories]


AS


SELECT * FROM Category WHERE CategoryID IN


( SELECT CategoryID FROM Product )


SELECT p.PID , p.ImageName,p.ProductName,p.Price,p.CategoryID FROM Product p


Design coding: I used nested repeater to get results according to category wise:


C sharp code:



protected void Page_Load(object sender, EventArgs e)
{

BindData();

}

private void BindData()
{
SqlConnection myConnection = new SqlConnection("Data Source=mypc;Initial Catalog=kk;user id=sa;password=ok; ");
SqlCommand myCommand = new SqlCommand("usp_GetProductsForCategories", myConnection);
myCommand.CommandType = CommandType.StoredProcedure;
SqlDataAdapter ad = new SqlDataAdapter(myCommand);
DataSet ds = new DataSet();
ad.Fill(ds);
// Attach the relationship to the dataSet
ds.Relations.Add(new DataRelation("CategoriesRelation", ds.Tables[0].Columns["CategoryID"],
ds.Tables[1].Columns["CategoryID"]));
outerRep.DataSource = ds.Tables[0];
outerRep.DataBind();

}

protected void outerRep_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
if (e.Item.ItemType == ListItemType.Item ||
e.Item.ItemType == ListItemType.AlternatingItem)
{
DataRowView drv = e.Item.DataItem as DataRowView;
Repeater innerRep = e.Item.FindControl("innerRep") as Repeater;
innerRep.DataSource = drv.CreateChildView("CategoriesRelation");
innerRep.DataBind();

}
}


I did not work previously in ms access for web application and I don't have knowledge of ms access.



asked 28 secs ago






Aucun commentaire:

Enregistrer un commentaire