Reputation: 16147
How come this line of code mine shows an error of
var searchUser = from accnt_user in dbo.Accounts
where accnt_user == txtUser.Text &&
accnt_Pass == txtPassword.Text
select accnt_user;
Error 2 The name 'accnt_Pass' does not exist in the current context C:\Users\John\documents\visual studio 2010\Projects\PAS\PAS\Login.cs 39 66 PAS
Error 1 The name 'dbo' does not exist in the current context C:\Users\John\documents\visual studio 2010\Projects\PAS\PAS\Login.cs 38 49 PAS
But I already my datacontext linked to it
DataClasses1DataContext myDbContext = new DataClasses1DataContext(dbPath);
And My DataClasses1DataContext already have this line of code
[global::System.Data.Linq.Mapping.TableAttribute(Name="dbo.Accounts")]
public partial class Account : INotifyPropertyChanging, INotifyPropertyChanged
NOTE: I have not added all of the code in the datacontext since it is long
Upvotes: 1
Views: 5545
Reputation: 185703
You aren't using the context in your query. Also, all column names must be prefixed by the alias defined for the source table or join (unlike SQL, where you can omit the prefix if the column is unique across the set of tables or views in the query).
Change your code to look like this:
using(DataClasses1DataContext myDbContext = new DataClasses1DataContext(dbPath))
{
var searchUser = from user in myDbContext.Accounts
where user.accnt_user == txtUser.Text &&
user.accnt_Pass == txtPassword.Text
select user;
// do something with searchUser
}
This is essentially equivalent to this SQL:
select user.*
from dbo.Accounts user
where user.accnt_user = @user and user.accnt_pass = @pass
Upvotes: 0
Reputation: 15881
try like this, as accnt_user
this will be the object of Accounts, so you need to access its all member by using .
operatorr
var searchUser = from accnt_user in Accounts
where accnt_user.accnt_user== txtUser.Text &&
accnt_user.accnt_pass== txtPassword.Text
select accnt_user;
Upvotes: 2