Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
20
WebDataGrid Databinding Flat DataSource
posted

Hi ,

I havent seen any example for Runtime databinding with Relationship based DataSet.I wanna do this scenario in my site.

 I have got Access Database.There is two table with relationship many to one named Products and Categories.So i wanna show my Foreign table's data in a ComboBox include in WebdataGrid.And for CRUD operations i wanna do this manually like getting values from rows and send this values to database. And if ya write me an example for this i will be happy.

So here is my codes;

protected void Page_Load(object sender, EventArgs e)

{

string conStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=";

conStr += Server.MapPath("~/App_Data/demo.mdb");

dbCon = new System.Data.OleDb.OleDbConnection(conStr);

dbCon.Open();

if (!Page.IsPostBack)

{

buildGrid();

 }

}

 private void buildGrid()

{

string sql;

sql = "SELECT * FROM Products";

System.Data.OleDb.OleDbDataAdapter daSrc = new System.Data.OleDb.OleDbDataAdapter(sql, dbCon);

DataTable oTable1 = new DataTable("Products");

daSrc.Fill(oTable1);

sql = "SELECT * FROM Categories";

daSrc = new System.Data.OleDb.OleDbDataAdapter(sql, dbCon);

DataTable oTable2 = new DataTable("Categories");

daSrc.Fill(oTable2);

DataSet dsSrc = new DataSet();

dsSrc.Tables.Add(oTable1);

dsSrc.Tables.Add(oTable2);

dsSrc.Relations.Add(dsSrc.Tables["Categories"].Columns["CategoryId"], dsSrc.Tables["Products"].Columns["CategoryId"]);

WebDataGrid1.DataSource = dsSrc;

 }