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?

Recommended Answers

All 2 Replies

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
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.