I'm totally new to this, as will be evident, and I can't figure out the syntax for what should be the most basic code.

I'm just trying to get a piece of data from a SQL database and store it in a variable. From various book and websites, I cobbled together the mess below. What I'm attempting (using LINQ to SQL) is to get a value from the "Password" field of a database, and compare it to a string entered into a text box web control:

string LoginName = Login_TextBox.Text;
        string PasswordString = Password_Textbox.Text;
        using (Link2StoryListDataContext db = new Link2StoryListDataContext())
            var theP =
                from p in db.Admins
                where p.Login is LoginName
                select p.Password;

             var thePW = db.ExecuteQuery(theP);

I also tried variations of this instead:

var theResults = db.ExecuteQuery("select db.Password where db.Login = LoginName");

Can some kind soul point me in the right direction?

Edited by JimOneill: left in bad extraneous code

7 Years
Discussion Span
Last Post by jdsurgeon

What helped me getting started with linq was LinqPad. It allows you to write and convert queries and execute them against your database. You can write sql, the app will convert it to linq. Nice way of getting used to it.


I'm not good at c# so i wrote it in vb.net hope you can still understand this.

dim db as new you datacontext
dim login as string
dim password as string

login = textbox1.text
password = textbox.text


dim getlogin = (from alias in db.users
                where alias.username = login
                select alias.password).First
if getlogin = password then

your logic

end if
catch ex as InvalidOperation Exception
dim message as string ="Username does not exists"
end catch

Edited by jdsurgeon: n/a

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.