Hi, I just upgraded to version 4.0 and added an external communication foreign key to my database. I would like to join table 2 User and Staffand return to the user interface. The staff table has a UserId. I must say that whenever a username is clicked on a datagridview, I would like to display the user and personnel data in the entire text box.
I am using tuple
public IEnumerable<Tuple<User, Staff>> Get()
{
using (qDataContext db = new qDataContext())
{
try
{
var r = from u in db.Users
join s in db.Staffs on u.Id equals s.UserId
select new Tuple<User, Staff>(u, s);
return r;
}
catch (Exception ex)
{
throw;
}
}
}
But in the user interface, how do I bind?
gvUser.DataSource = user.Get();
FYI, gridview just displays the username. The employee table stores the password, fields marked with a date.
By the way, I still need to join tables, since I already added a link to foreign keys for tables .. I think this should be smart enough to return User.Staff.Password to me
, ..
.
Staff.UserId UserId
And i don have to use the TUPLE to return those object :)!!
public IEnumerable<User> Get()
{
using (ZebraDataContext db = new ZebraDataContext())
{
try
{
var r = from u in db.Users
select u;
return r.ToList();
}
catch (Exception ex)
{
throw;
}
}
}
, GUI.
private void InitializeData()
{
gvUser.DataSource = user.Get();
}
. Staff, gvUser_RowEnter?
private void gvUser_RowEnter ( , DataGridViewCellEventArgs e) { if (e.RowIndex <= 0) return;
foreach (DataGridViewRow row in gvUser.SelectedRows)
{
User user = row.DataBoundItem as User;
txtName.Text = user.Name;
txtAddress.Text = user.Address;
txtPhone.Text = user.Phone;
txtPhone2.Text = user.Phone2;
txtRemark.Text = user.Remarks;
txtPassword.Text = user.Staffs.First().Password;
}
}
txtPassword.text = user.Staffs.First().Password ==
.
: " DataContext Dispose.".
Staff .
(() (row.DataBoundItem)). Staffs.entities.Items .