0

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

2
Contributors
5
Replies
6
Views
7 Years
Discussion Span
Last Post by judithSampathwa
0

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

0

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

0

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

0

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

0

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

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.