String check = Data.Logins.Where(Login=>Login.Username==TextBoxnewusername.Text)
I have a table named "Login".
There are 4 columns - Username, password, Name, Address.
The Username column is of data type nvarchar(max).
The 'TextBoxnewusername.Text' is a textbox where new users input their user name.
Now, the error is as follows-
Cannot implicitly convert type 'system.linq.IQueryable' to 'String'.
Any idea how to correct it?? Is there any casting it?
Nigel FernandesPosted Aug 6, 2017, 8:40 PM
Sayan ChatterjeePosted Aug 9, 2017, 11:01 AM
{
using (ShopDataContext Data = new ShopDataContext())
{
Login newlogin = new Login(); //Creating instance of the 'Login' table//
var check = Data.Logins.Where(Login => Login.Username==TextBoxnewusername.Text); //Lambda expression//
foreach (Login output in check)
{
if (output.Username != TextBoxnewusername.Text)
{
newlogin.Name = TextBoxname.Text;
newlogin.Username = TextBoxnewusername.Text;
newlogin.Address = TextBoxaddress.Text;
newlogin.password = TextBoxnewpassword.Text;
Data.Logins.InsertOnSubmit(newlogin);
Data.SubmitChanges();
Labelmessage.Text = "Successful";
}
else
{
Labelmessage.Text = "User name already exists in the database, pls. select a new username";
}
}
}
}
Rajkiran SwainPosted Aug 8, 2017, 12:48 PM
Rijwan AnsariPosted Aug 8, 2017, 12:13 PM
Gnanavel SekarPosted Aug 6, 2017, 9:43 PM
D DonthuPosted Aug 6, 2017, 1:38 PM