hi there,
i have a question in LINQ in C#,
i have a webpage and in that i have a button called clicl and theGridview . i have a LINQ to SQL class with the Employee and the USErLogin which the EID in the Employee calss is a foreign key in the USerlogin class,
i doubled click on the button and wrote a simple query to get the values from the Employee table
below is the code

protected void Button1_Click(object sender, EventArgs e)
    {
       var query = from e2 in po.Employees
                    select e2;

        GridView1.DataBind();
        GridView1.DataSource = query;
    }

but when i click the buttonnothis appears or no error , but the mdf file that i am using has values, why is this happening??

please give me a solution
appreciate a lot,
also i am not sure if i am in the right forum,
thanxx
appreciate a lot

I guess the order should be

protected void Button1_Click(object sender, EventArgs e)
{
    var query = from e2 in po.Employees
                select e2;

    GridView1.DataSource = query; // this should come first.
    GridView1.DataBind();
}

I would like to know if that worked, I am kinda rough around edges when it comes to GridViews :P

I guess the order should be

protected void Button1_Click(object sender, EventArgs e)
{
    var query = from e2 in po.Employees
                select e2;

    GridView1.DataSource = query; // this should come first.
    GridView1.DataBind();
}

I would like to know if that worked, I am kinda rough around edges when it comes to GridViews :P

hey thankxxx
and also my table structure is as below

create table Employee(
EID int primary key,
Name string,
);
create table UserLogin(
ID int primary key,
Username string,
Password string,
EID int foreign key
);

but when i write the below query

var a = from b in po.GetTable<Employee>()
                where [B]b.Userlogins.EID[/B] == b.EID && b.Userlogins.Username == "krishni" && b.Userlogins.Password == "123"
                select b;

       
        GridView1.DataSource = a;
        GridView1.DataBind();

it says the b.Userlogins.EID hasn't EID wher it is bold and the Userlogin parameters does not come as drop down,

why is this??

please can you guide me with this
thanxxxxx

The table name is "UserLogin" or "UserLogins"? or is it the way it has been mapped in DataContext?

The table name is "UserLogin" or "UserLogins"? or is it the way it has been mapped in DataContext?

table name is UserLogin but the visual studio gives the UserLogins as a drop down???

why is that

table name is UserLogin but the visual studio gives the UserLogins as a drop down???

why is that

hey bu the way
is the below code corrent
i tried it in another way

string uname = Login1.UserName;
        string pass = Login1.Password;

        var query = from e1 in po.GetTable<Employee>()
                    from u in po.GetTable<Userlogin>()
                    where (u.Username == uname && u.Password == pass)
                    select e1.Name;

        GridView1.DataSource = query;
        GridView1.DataBind();

thanxxx
appriciate a lot

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.