Friday, August 02, 2013

Save Button Code in ASP.Net

First Insert these lines at the top of code bind file

using System.Data;
using System.IO;
using System.Configuration;
using System.Data.SqlClient;


Second step is to write this line inside your class

string _connStr = ConfigurationManager.ConnectionStrings["connectionString"].ConnectionString;


Third step is to write this code in save button event


protected void btnsubmit_Click(object sender, EventArgs e)
    {
        try
        {
            String struserid, strpassword, strfirstname, strmiddlename, strlastname;
            String stremailid, strmobilenumber, strcollegename;
            struserid = txtuserid.Text;
            strpassword = txtpassword.Text;
            strfirstname = txtfirstname.Text;
            strmiddlename = txtmiddlename.Text;
            strlastname = txtlastname.Text;
            stremailid = txtemailid.Text;
            strmobilenumber = txtmobile.Text;
            strcollegename = txtcollegename.Text;
            SqlConnection con = new SqlConnection();
            con.ConnectionString = _connStr;
            String strinsert = "insert into profiledata(userid,firstname,middlename,lastname,emailid,mobile,collegename,password) values('" + struserid + "','" + strfirstname + "','" + strmiddlename + "','" + strlastname + "','" + stremailid + "','" + strmobilenumber + "','" + strcollegename + "','" + fileName + "','" + imageBytes + "','" + strpassword + "')";
            con.Open();

            SqlCommand cmd = new SqlCommand(strinsert, con);
            cmd.ExecuteNonQuery();
            con.Close();
        }
        catch (Exception exp)
        {
            Label1.Text = "Error in inserting Data";
        }



    }

Sign In Code in ASP.Net

First Insert these lines at the top of your code bind file.

using System.Data;
using System.Configuration;
using System.Data.SqlClient;

Second step is to write this code in signin button event

protected void btnSignIn_Click(object sender, EventArgs e)
    {
        String struserid = txtuserid.Text;
        String strpassword = txtpassword.Text;
        if (struserid == "" && strpassword == "")
        {
            Label1.Text = "Please Valid User ID";
            Label2.Text = "Please Fill Valid Password";
        }
        else
        {
            SqlConnection con = new SqlConnection();
            con.ConnectionString = _connStr;
            String strselect = "select userid,password from profiledata where userid='" + struserid + "' and password='" + strpassword + "'";
            con.Open();
            SqlCommand cmd = new SqlCommand(strselect,con);
            SqlDataReader dr = cmd.ExecuteReader();
            if (dr.Read())
            {
                Session["sessionuserId"] = struserid;
                ScriptManager.RegisterStartupScript(Page, typeof(Page), "OpenWindow", "window.open('mygallary.aspx','frame1');", true);
             
            }
            else
            {
                Label1.Text = "Please Valid User ID";
                Label2.Text = "Please Fill Valid Password";
         
            }

        }
    }