Search

Thursday, February 26, 2015
One comments

Custom login control using edmx file in windows forms application C#

8:50 PMThursday, February 26, 2015

Introduction

Login contol provide some privilege to the project or you can say its a entry point of the project. Though this form we can move to the next form. If your input text is valid then move to the next but if your input is wrong then move failed. So, the main function of the project is check each entry of the table with the TextBox.

Design login control in windows form


  1. Add Two TextBox with the label control.
  2. Add one button control with click event , Look like
login control in windows form

Add EDMX file with the help of following steps:

  1. Add ADO.NET Entity Data Model by the add new item component.
  2. Add ADO.NET Entity Data Model
  3. Now, select EF designer from database in the entity data model wizard.
  4. select EF designer from database
  5. Now create the connection by pressing the 'new connection' button , also select the check box where your connection string save into your application configuration file. Now, press to next button.
  6. Now create the connection by pressing the 'new connection' button
  7. Select entity framework version , i select 5.0 in the project.
  8. Select entity framework version , i select 5.0 in the project.
  9. Select table, views , stored procedure in the appeared window.
  10. Select table, views , stored procedure in the appeared window.
  11.  Now, your model look likeentity data model

Copy and paste the below code inside the button click event.


private void button1_Click(object sender, EventArgs e)
        {
            Student_DBEntities dc = new Student_DBEntities();
            if (usrBox.Text != string.Empty && pwdBox.Text != string.Empty)

            {
                var existuser = dc.admins.FirstOrDefault(a => a.userName.Equals(usrBox.Text));
                if(existuser!=null)
                {
                    if (existuser.Password.Equals(pwdBox.Text))
                        MessageBox.Show("Login Sucess");
                    else
                        MessageBox.Show("try again later");
                }

            }
        }

Here,
  1. Student_DBEntities is a DataContext , which is take connection string in the constructor. Also take public property of the model class, through this we can access all the data from database table.
  2. admins is the public property of data context class.
Code generate the following output - please see the video:

Protected by Copyscape Online Copyright Protection Software

1 comments :

  1. design tools, content-managing systems very nice.

    ReplyDelete

 
Toggle Footer
Top