this is my code for binding data from data base to text box

protected void Page_Load(object sender, EventArgs e)
    {
        label.Text = System.DateTime.Now.ToLongDateString();
        ////

        /// date label
        label.Text = System.DateTime.Now.ToLongDateString();
        appSession = (String)Session["applicantEmail"];
        lblusername.Text = (String)Session["applicantName"];
        lblusernamepic.Text = (String)Session["applicantName"];
        String str = " SELECT     tblPersonalInfo.firstname, tblPersonalInfo.lastname, tblPersonalInfo.fathername, tblPersonalInfo.country, tblPersonalInfo.city, tblPersonalInfo.phoneno,tblPersonalInfo.mobno, tblPersonalInfo.domicile, tblPersonalInfo.sect, tblPersonalInfo.cnicnum, tblPersonalInfo.mailingadd, tblPersonalInfo.permanentadd,tblUser.fullname, tblUser.email, tblUser.password, tblUser.question, tblUser.answers, tblUser.gender, tblUser.dob, tblUser.doc FROM tblPersonalInfo INNER JOIN tblUser ON tblPersonalInfo.userid = tblUser.userid WHERE  roleid=3 and   (tblUser.email = '" + (String)Session["applicantEmail"] + "')";
        //String str = "select fullname,email,password,question,answers,gender,dob,doc from tblUser where roleid=3 and email='" + (String)Session["applicantEmail"] + "'";
        SqlCommand cmd = new SqlCommand(str, con);
        con.Open();
        SqlDataReader dr = cmd.ExecuteReader();
        if (dr.Read())
        {
            txtfullname.Text = dr["fullname"].ToString();
            txtemail.Text = dr["email"].ToString();
            txtpassword.Text = dr["password"].ToString();
            txtquestion.Text = dr["question"].ToString();
            txtanswer.Text = dr["answers"].ToString();
            txtgender.Text = dr["gender"].ToString();
            txtdob.Text = dr["dob"].ToString();
            txtaccountcreate.Text = dr["doc"].ToString();
            txtfirstname.Text = dr["firstname"].ToString();
            txtlastname.Text = dr["lastname"].ToString();
            txtfathername.Text = dr["fathername"].ToString();
            txtcountry.Text = dr["country"].ToString();
            txtcity.Text = dr["city"].ToString();
            txtphoneno.Text = dr["phoneno"].ToString();
            txtmob.Text = dr["mobno"].ToString();
            txtdomicile.Text = dr["domicile"].ToString();
            txtsect.Text = dr["sect"].ToString();
            txtmailingaddress.Text = dr["mailingadd"].ToString();
            txtpermanent.Text = dr["permanentadd"].ToString();
        }
        con.Close();
        if (!IsPostBack)
        {
            BindAcademicDetails();
            BindExperienceDetails();
            BindPublicationsDetails();
        }

    }

is there any solution that the above bind data when changed by user and i get it for updating...???

    protected void update_Click(object sender, EventArgs e)
    {
        userid = Convert.ToInt32(Session["userid"]);
        username = (String)Session["applicantName"];
        con.Open();
        SqlCommand cmd = new SqlCommand("update tblUser set fullname='" + txtfullname.Text + "' where userid=" + userid, con);
        cmd.ExecuteNonQuery();
        con.Close();
    }

thanks in Advance !!

Recommended Answers

All 3 Replies

Member Avatar for LastMitch

is there any solution that the above bind data when changed by user and i get it for updating...???

I think it's this line is preventing the updating:

SqlCommand cmd = new SqlCommand("update tblUser set fullname='" + txtfullname.Text + "' where userid=" + userid, con);

Change it from this:

SqlCommand cmd = new SqlCommand("update tblUser set fullname='" + txtfullname.Text + "' where userid=" + userid, con);

To this:

SqlCommand cmd = new SqlCommand("update tblUser set fullname='" + txtfullname.Text + "'  where userid= '" + userid +"' ", con);    

this is my code for binding data from data base to text box

Take this out of the code and put it in a separate code:

if (!IsPostBack)
{
BindAcademicDetails();
BindExperienceDetails();
BindPublicationsDetails();
}

I think that should work not sure.

if you have an a code.. debug firts then see what is the problem..

If i want to update by use storeprocedure so i can update the record of database.

thanxx

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.