Basically I'm using LINQ to connect to a database(LoginDB) and the table (Korisnici) and see if there are entries in the username and password column that fit the entries of the Login1 Login Control.

The Error message is : Cannot implicitly convert type 'string' to 'bool'
Cannot implicitly convert type 'string' to 'bool' Operator '==' cannot be applied to operands of type 'System.Linq.IQueryable<LogInLINQ.Korisnici>' and 'string'
Operator '==' cannot be applied to operands of type 'System.Linq.IQueryable<LogInLINQ.Korisnici>' and 'string'


thanks for you help!!

using System;
using System.Collections.Generic;
using System.Data.Linq;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Xml.Linq;

namespace LogInLINQ
{
    public partial class logIn : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            TabelaLINQDataContext db = new TabelaLINQDataContext();

            var query = from korisnik in db.Korisnicis where korisnik.username = (string)Login1.UserName select korisnik;

            var query1 = from korisnik in db.Korisnicis where korisnik.password = Login1.Password.ToString() select korisnik;

            if ((query == Login1.UserName) && (query1 == Login1.Password))
            {
                Response.Redirect("Default.aspx");
            }

            else lblerror.Text = "You entered invalid username/password";


        }

        protected void LinkButton1_Click(object sender, EventArgs e)
        {
            Response.Redirect("signUp.aspx");
        }
    }
}

I would wager a good guess that is is due to the fact that you are trying to compare query and query1 to UserName and Password, respectively.

query and query1, by the linq syntax you provided will actually be of type korisnik.

You should be able to do something like query.username.Equals(Login1.UserName) and query1.password.Equals(Login1.Password)

I am not sure if korisnik.username = (string)Login1.UserName will work as you intended, as = is an assignment, not an evaluator. You may try the == or .Equals

You can combine these into one statement if you prefer like:

var query = (from korisnik 
             in db.Korisnicis
             where korisnik.password == Login1.Password && korisnik.username == Login1.UserName
             select korisnik).FirstOrDefault();

from there you can simply check if query is null or not. If it is, no matches were found. If its not null, a match was.

Hope that helps.

Also, this is really C#, not asp.net.... just an FYI for future posts.

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.