Saturday 5 August 2017

Code on Submit button click for Submit data in ASP.Net?

In the previous posts , I clearly describe following things

Step1 : How to create database and table into database (Please read previous post)

Step2: After creating the table ,so we have to provide connetion string in web.config file, we need to provide connection string for establishments of  connection between ASP.Net application and SQL Server so i describe it in the post
How to set connection string in web.config file.(Please read previous post)

Step 3 : For Inserting data we require User Interface or web form , So in my previous post I describe How to design a web form.(Please read previous post)

Step 4 : Code for Entity Layer(Please read previous post)

Step 5: Code for DataLayer(Please read previous post)

Step6: Code on Button click (Learn in this post)

In This post we learn about how to call methods defined into the Datalayer and how to use properties defined in the EntityLayer.
 Complete code is given below copy and paste in your application and run it .

int genderid;
    protected void btnSave_Click(object sender, EventArgs e)
    {
        try
        {
       
            studentregistration_BEL objStudent_BEL = new studentregistration_BEL();
            studentregistration_DAl objStudent_DAL = new studentregistration_DAl();
            objStudent_BEL.FirstName = txtFirstName.Text;
            objStudent_BEL.LastName = txtLastName.Text;
            objStudent_BEL.UserName = txtUserName.Text;
            objStudent_BEL.Password = txtPassword.Text;
            objStudent_BEL.Mobile = txtPhone.Text;
            objStudent_BEL.DOB = Convert.ToDateTime(txtDob.Text);
            objStudent_BEL.Email = txtEmailAddress.Text;

            if (rbFemale.Checked == true)
            {
                genderid = 1;
            }
            if (rbMale.Checked == true)
            {
                genderid = 2;
            }
            else
            {
                Response.Write("Please select Gender");
            }
  objStudent_BEL.GenderID=genderid  ;
            objStudent_DAL.RegisterStudent(objStudent_BEL);
            Response.Write("Student Registered");
        }
        catch(Exception ex)
        {
            Response.Write(ex.Message);
        }
    }

No comments:

Post a Comment

Creating First WEB API Project from scratch ?

  For creating Web API project open your Visual Studio Editor and Create New Project as shown in below figure. Now you have to select  ASP.N...