Click here to Skip to main content
15,886,258 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
C#
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;

public partial class profile : System.Web.UI.Page
{
    SqlDataReader dr;
    SqlConnection con = new SqlConnection(@"Data Source=MAY-PC\SQLEXPRESS;Initial Catalog=demo;Integrated Security=True");
    protected void Page_Load(object sender, EventArgs e)
    {
        pname.Text = Session["userid"].ToString();
        read();

    }
    protected void savebtn_Click(object sender, ImageClickEventArgs e)
    {
       
        //int imagefilelenth = FileUpload1.PostedFile.ContentLength;
       // byte[] imgarray = new byte[imagefilelenth];
       // HttpPostedFile image = FileUpload1.PostedFile;
       //image.InputStream.Read(imgarray, 0, imagefilelenth);

        SqlCommand cmd = new SqlCommand("[update]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@email", pemail.Text.ToString());
        cmd.Parameters.AddWithValue("@dob", pdob.Text.ToString());
        cmd.Parameters.AddWithValue("@gender", pgender.Text.ToString());
        cmd.Parameters.AddWithValue("@city", city.Text.ToString());
        cmd.Parameters.AddWithValue("@state", state.Text.ToString());
        cmd.Parameters.AddWithValue("@country", country.Text.ToString());
        cmd.Parameters.AddWithValue("@about", about.Text.ToString());
        cmd.Parameters.AddWithValue("@books", books.Text.ToString());
        cmd.Parameters.AddWithValue("@qualification", qualification.Text.ToString());
        cmd.Parameters.AddWithValue("@number", number.Text.ToString());
        //cmd.Parameters.AddWithValue("@image",imgarray);
        cmd.Parameters.AddWithValue("@username", pname.Text.ToString());
        cmd.Parameters.AddWithValue("@designation", designation.Text.ToString());
        cmd.Parameters.AddWithValue("@interest", interest.Text.ToString());
        con.Open();
        cmd.ExecuteNonQuery();
        con.Close();
                        
                                        
    }
    protected void cancelbtn_Click(object sender, ImageClickEventArgs e)
    {
        Response.Redirect("viewprofile1.aspx");
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {

            string path = "~/imguplod/" + (FileUpload1.FileName);
            FileUpload1.SaveAs(Server.MapPath(path));
            Image1.ImageUrl = path;
            Session["image"] = (FileUpload1.FileName);

        }
    }

    private void read()
    {
        SqlCommand cmd = new SqlCommand("[select]", con);
        cmd.CommandType = CommandType.StoredProcedure;
        cmd.Parameters.AddWithValue("@username", pname.Text.ToString());
        con.Open();
        dr = cmd.ExecuteReader();

       
        if (dr != null && dr.HasRows)
        {

           dr.Read();
        
        {
        pname.Text = (Convert.ToString(dr["username"]));
        pdob.Text = (Convert.ToString(dr["dob"]));
        pemail.Text = (Convert.ToString(dr["email"]));
        pgender.Text = (Convert.ToString(dr["gender"]));
        city.Text = (Convert.ToString(dr["city"]));
        state.Text = (Convert.ToString(dr["state"]));
        country.Text = (Convert.ToString(dr["country"]));
        designation.Text = (Convert.ToString(dr["designation"]));
        qualification.Text = (Convert.ToString(dr["qualification"]));
        about.Text = (Convert.ToString(dr["about"]));
        interest.Text = (Convert.ToString(dr["interest"]));
        books.Text = (Convert.ToString(dr["books"]));        
        con.Close();
        }
        }
         else 
        {
        pname.Text = Session["userid"].ToString();
        pemail.Text = Session["email"].ToString();
        pgender.Text = Session["gender"].ToString();
        pdob.Text = Session["dob"].ToString();
        }
    }
    
}
Posted
Updated 12-Mar-14 23:16pm
v4
Comments
Ankur\m/ 13-Mar-14 4:20am    
You haven't mentioned what doesn't work, what error did you get?
bhagyadeep 13-Mar-14 4:23am    
i got fatch data in textbox and update date in database table but update not work....
Ankur\m/ 13-Mar-14 4:25am    
1. Did you verify if the values are passing correctly? If yes, go to 2.
2. Before calling ExecuteNonQuery method, take the query that is build. Run that against SQL query analyzer and check the result.
bhagyadeep 13-Mar-14 4:32am    
ya i not used reader then work update quary and problem in city.Text.ToString() and all string not get value!!!!!!
bhagyadeep 13-Mar-14 4:34am    
for select


ALTER PROCEDURE [dbo].[select]
@username varchar(50)
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

select * from registration where username=@username
END



for update


ALTER PROCEDURE[dbo].[update]
@username varchar(50),@email varchar(50),@dob date,@gender varchar(50),@city varchar(50),@state varchar(50),@country varchar(50),@designation varchar(50),@qualification varchar(50),@about varchar(50),@interest varchar(50),@books varchar(50),@number int
AS
BEGIN
-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

update registration set email=@email,dob=@dob,gender=@gender,city=@city,[state]=@state,country=@country,designation=@designation,qualification=@qualification,about=@about,interest=@interest,books=@books,number=@number where username=@username
END

1 solution

You need to start by looking at what your "update" stored procedure does - we can't because we have no access to your database.
In all probability, it includes an SQL WHERE clause that isn't matching, which may mean you are passing the wrong information.

But until you look at it, no one can tell.

BTW: There is no need at all to call ToString on Text properties, unless they are defined by you and are not string type already. And if you have defined properties called Text that aren't strings, then you need to change them! :laugh:
 
Share this answer
 
Comments
bhagyadeep 13-Mar-14 4:41am    
not in all number and image collumb are update
OriginalGriff 13-Mar-14 5:12am    
That really isn't very helpful, you know - it tells us pretty much nothing we didn't already know... When you have a problem, tell us exactly what happens, because we can't see your screen!

A quick look at your SP says it's one of two things: either your username isn't matching any rows in the DB, or the SQL is throwing an exception - so you need to look at both of those and work out which.

The first is pretty easy: check the return value from ExecuteNonQuery and see how many rows are affected - and report it so you can see what happened.
The second is a bit harder: add a try...catch block round the DB access in the save button click method and report success or fail to a label on the webpage.

We can;t do either of these for you: so try it out and see what you get.
bhagyadeep 13-Mar-14 5:38am    
actolly i dont fatch data in control so work bt i fatch data in conyroler then not work update..................
OriginalGriff 13-Mar-14 6:08am    
Sorry? That makes no sense whatsoever!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900