Click here to Skip to main content
15,868,016 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more: , +
I wrote a login form with wpf and entityframework but I have a problem coding. The following error is taken


The variable login definition line takes the following error.

What I have tried:

C#
private void btnVoroud_Click(object sender, RoutedEventArgs e)
        {
            IDMS_dbEntities db = new IDMS_dbEntities();
            var login = db.tblUsers.Single();
            if (txtKarbari.Text == login.UserName && txtPassword.Password.ToString() == login.Password)
            {
                this.Hide();
                WinRemainder win = new WinRemainder();
                win.ShowDialog();
            }
            else
            {
                lblMessage.Visibility = Visibility.Visible;
                lblMessage.Content = "نام کاربری یا رمز عبور اشتباه می باشد";
                txtKarbari.Text = "";
                txtPassword.Password = "";
                mohlat--;
                if (mohlat == 0)
                {
                    lblMessage.Content = "تعداد دفعات ورود رمز تمام شد";
                    mohlat = 4;
                    btnVoroud.IsEnabled = false;

                }
            }
	}





Exception thrown: 'System.Data.Entity.Core.EntityCommandCompilationException' in EntityFramework.SqlServer.dll

Additional information: An error occurred while preparing the command definition. See the inner exception for details.


tblUser:
CREATE TABLE [dbo].[tblUser] (
    [Id]       INT           IDENTITY (1, 1) NOT NULL,
    [Name]     NVARCHAR (50) NULL,
    [Family]   NVARCHAR (50) NULL,
    [UserName] NVARCHAR (50) NOT NULL,
    [Password] NVARCHAR (50) NULL,
    CONSTRAINT [PK_tblUser] PRIMARY KEY CLUSTERED ([UserName] ASC)
);



I hope you understand the meaning of my question because I do not know English anymore
Posted
Updated 12-Dec-18 20:55pm
v3
Comments
Richard Deeming 14-Dec-18 10:42am    
Member 14006859 14-Dec-18 20:36pm    
Hello
I'm having trouble with this line of code (var login = db.tblUsers.Single();). I do not care about security at the moment

1 solution

Look at your error message:
Exception thrown: 'System.Data.Entity.Core.EntityCommandCompilationException' in EntityFramework.SqlServer.dll

Additional information: An error occurred while preparing the command definition. See the inner exception for details.
So use the debugger, and look at the InnerException: it will contain details which hopefully should help you.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900