Saurabh Bhardwaj

Saurabh Bhardwaj

  • NA
  • 14
  • 14.2k

Data not stored in database

Dec 11 2012 4:31 AM
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.SqlClient;
using System.Drawing;

public partial class allrishteymaster : System.Web.UI.MasterPage
{
    string constr = ConfigurationManager.ConnectionStrings["constr"].ToString();
    protected void Page_Load(object sender, EventArgs e)
    {
        //start making session
        Session["email"] = Textmail;
        Session["password"] = Textpassword;
        Session["profilefor"] = profilefor;
        Session["name"] = Textusername;
        Session["gender"] = Radiomale;
        Session["gender"] = Radiofemale;
        Session["dd"] = dd;
        Session["mm"] = mm;
        Session["yy"] = yy;
        Session["religion"] = religion;
        Session["mothertongue"] = mothertongue;
        Session["livingin"] = livingin;
        //end making session
    }
    protected void regissub_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(constr);
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter("select email from userregisteration where email='" + Textmail + "'", con);
        DataSet ds = new DataSet();
        da.Fill(ds, "userregisteration");

        if (ds.Tables[0].Rows.Count > 0)
        {

            error.Text = "User Name Already Exits";

        }
        else if (Checkbox1.Checked == true)
        {
            SqlCommand cmd = new SqlCommand("insert into userregisteration(uid,email,password,prpofilefor,username,gender,dob,religion,mothertongue,livingin) values(@uid,@email,@password,@prpofilefor,@username,@gender,@dob,@religion,@mothertongue,@livingin)", con);
            cmd.Parameters.Add(new SqlParameter("@uid", Session["uid"]));
            cmd.Parameters.Add(new SqlParameter("@email", Textmail));
            cmd.Parameters.Add(new SqlParameter("@password", Textpassword));
            cmd.Parameters.Add(new SqlParameter("@prpofilefor", profilefor));
            cmd.Parameters.Add(new SqlParameter("@username", Textusername));
            cmd.Parameters.Add(new SqlParameter("@gender", Radiomale));
            cmd.Parameters.Add(new SqlParameter("@gender", Radiofemale));
            cmd.Parameters.Add(new SqlParameter("@dob", dd.SelectedIndex + "-" + mm.SelectedIndex + "-" + yy));
            cmd.Parameters.Add(new SqlParameter("@religion", religion));
            cmd.Parameters.Add(new SqlParameter("@mothertongue", mothertongue));
            cmd.Parameters.Add(new SqlParameter("@livingin", livingin));
            //cmd.ExecuteNonQuery();
            con.Close();
            Response.Redirect("RgistrationProfile2.aspx");
        }
        else
        {
            error.Text = "Please Select Privacy Policy and T&C";
        }
 
    }
   
}


Answers (2)

0
arjun

arjun

  • 1.3k
  • 50
  • 2.4k
Dec 19 2012 2:08 AM
hi,
    I think its not good idea writing code in MasterPage...
write the code in data layer and access from bussiness layer.and never use that much number of sessions...
0
MANJUNATH yattinagudd

MANJUNATH yattinagudd

  • 0
  • 2
  • 0
Dec 11 2012 5:42 AM
use following to catch error

try
{ //do stuff } finally { //clean up }


catch(Exception ex) { throw ex; }