DataGrid and SQL Server

  • Thread starter Thread starter DarkWing
  • Start date Start date
D

DarkWing

Hello Every one i had a question
i am setting up an DataGrid with use of MS SQL server
in my sqlserver i have 2 tables

1-UserList(which containes Employee's Name)(has 13
elements,eg 13 employees)
2-ScheduleSetting(Which Containes Employees hours of
avilbilites to work)(has 13 elements)

Now my dataGrid is trying to recived infromation from
these 2 tables..i have no problem in that...where the
problem arises is when executing the bindGridData() method
****
private void bindGridData(){
sCmd = new SqlCommand("SELECT hpw, u_username
FROM UserList, scheduleSetting", conn);

try{
conn.Open();
hpwGrid.DataSource=sCmd.ExecuteReader();
hpwGrid.DataBind();
conn.Close();
}catch(Exception e){
this.errorMessage=e.ToString();
}

}
*****
every element in UserList tabel matches 13 times with
every element of ScheduleSetting..so i end up having
something like this

eg

Alex 1hr
Alex 2hr
Alex 3hr
.. .
.. .
Alex 13hr
Jen 1hr
Jen 2hr
.. .
.. .
Jen 13hr

now both of my tables have U_id colums in them(which are
excatly the same) i just dont know how to set up my
method to match each u_id so it would show something like
this instead

Alex 1hr
Jen
 
well cartisian product... that is what you are getting....
what you need is a smart query which returns you one datatalbe ie the query
will perform the required join.

select userlist.employeename, schedulesettings.availablehours
from userlist, schedulesettings
where userlist.employeeid=schedulesettings.employeeid

something like that.
once you have required data in a single datatable within DataSet
go and bind it to you datagrid and you will be fine

Hermit Dave
 
Back
Top