Hi
I am new to programing and learing c#. I am trying to create a windows based form which find the record from data base. The data base have three form Repair, customer and machine. The search criteria is when user enter repair ID the result populate into three grides one with all customer inoformation against that repair Id and one is to show repaie information and last one is to show machine information. My problem is how can I show the records into three grids using one Join query.
Thanks
Loading

Bechir BejaouiRank #144 · 15.9K reputationPosted Feb 1, 2009, 1:07 PM EST
always gull30 reputationPosted Feb 16, 2009, 10:30 AM EST
Tables
customer(Id, name, add,tel, email)
Repair(RepId, CusId,MachId,Redescription, RepStatus, RepCost) Machine(MachId,CusId,Make,Model,SerielNo)
Relation ships
1 Customer can have many repairs many Repair can have many customer
1 Customer can have many machine for repair Many machine can have many Cus
1 Machine can be repair many time Many repair can have same machine for repair
Thanks
LisaRank #8,652 · 218 reputationPosted Feb 17, 2009, 1:02 AM EST
you can create a query with actually returns 3 datasets or may be single dataset with 3 different tables and assign those values to the indivdual datagrid views.
Thanks,
Lisa
always gull30 reputationPosted Feb 17, 2009, 3:39 AM EST
Thanks Israr
LisaRank #8,652 · 218 reputationPosted Feb 17, 2009, 4:28 AM EST
well consider a query like
select * from table1
select * from table2
select * from table3 in a single procedure this will return 3 different results
you can then use a dataadapter to fill the dataset with 3 different tables in the same dataset
and assign individual tables to datagridviews.
Thanks,
Lisa
always gull30 reputationPosted Feb 17, 2009, 7:05 AM EST
LisaRank #8,652 · 218 reputationPosted Feb 17, 2009, 8:42 PM EST
thats quite simple
say dg1 is your first datagrid
dg1.DataSource = ds.Tables[0]
dg2.DataSource = ds.Tables[1]
dg3.DataSource = ds.Tables[2]
be sure which table goes to which datagrid.
Thanks,
Lisa
makando kabila8 reputationPosted Feb 21, 2009, 3:36 AM EST
This approach also could be useful if you select a row from one of the datagrids and then to only display the
corresponding ones in the other grids. There're various ways to do this.
Part of your code listing could be something like this:
DataView dvCustomers;
DataView dvRepairs;
DataView dvMachines;
DataSet ds = new DataSet();
private void Form1_Load(object sender, EventArgs e)
{
//Populate the dataset first
//Then
InitialiseDataviewsAndBind();
}
private void btnFindRecords_Click(object sender, EventArgs e)
{
string repairid = "your RepId comes here";
//or string repairid = textBox1.Text;
ApplyFilter(repairid);
}
private void ApplyFilter(string repairid)
{
string custfilter = string.Empty;
string machinefilter = string.Empty;
dvRepairs.RowFilter = "RepairId='" + repairid + "'";
if (dvRepairs.Count > 0)
{
DataRowView drvrepairs = dvRepairs[0];
custfilter = "Id='" + drvrepairs["CusId"].ToString() + "'";
machinefilter = "MachId='" + drvrepairs["MachId"].ToString() + "'";
}
dvCustomers.RowFilter = custfilter;
dvMachines.RowFilter = machinefilter;
}
private void InitialiseDataviewsAndBind()
{
/* Run after populating your dataset
*You could use table names if you know them correctlt
*instead of the index*/
dvCustomers = ds.Tables[0].DefaultView;
dvRepairs = ds.Tables[2].DefaultView;
dvMachines = ds.Tables[3].DefaultView;
dg1.DataSource = dvCustomers;
dg2.DataSource = dvRepairs;
dg3.DataSource = dvMachines;
}
always gull30 reputationPosted Feb 25, 2009, 8:51 AM EST
Thanks