更新asp.net网页的详细信息? [英] Update details in asp.net web page?

查看:103
本文介绍了更新asp.net网页的详细信息?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

亲爱的所有人,



我正在开发1个网站

注册后登录并登录客户更新个人资料



我写了这段代码:



Dear All,

am developing 1 web site
here after register and login the customer updates the profile

I wrote this code:

string connectionString = ConfigurationManager.ConnectionStrings["masthanConnectionString"].ConnectionString;
        string strUpdate = "UPDATE Registration SET FirstName = @FirstName, LastName = @LastName, Gender = @Gender, DOB=@DOB, Password = @Password, ConfirmPassword = @ConfirmPassword, Mobile=@Mobile, Address=@Address, City=@City, State=@State,PIN=@PIN,Iam=@Iam WHERE Password = @CurPassword";
        //Create SQL connection
        SqlConnection con = new SqlConnection(connectionString);

        //Create SQL Command And Sql Parameters

        SqlCommand cmd = new SqlCommand();
        cmd.Connection = con;
        cmd.CommandType = CommandType.Text;
        cmd.CommandText = strUpdate;

        SqlParameter FirstName = new SqlParameter("@FirstName", SqlDbType.VarChar, 50);
        FirstName.Value = txtFName.Text.ToString();
        cmd.Parameters.Add(FirstName);

        SqlParameter LastName = new SqlParameter("@LastName", SqlDbType.VarChar, 50);
        LastName.Value = txtLName.Text.ToString();
        cmd.Parameters.Add(LastName);

        SqlParameter Gender = new SqlParameter("@Gender", SqlDbType.VarChar, 50);
        Gender.Value = rblGender.SelectedItem.ToString();
        cmd.Parameters.Add(Gender);

        SqlParameter DOB = new SqlParameter("@DOB", SqlDbType.VarChar, 20);
        DOB.Value = txtDOB.Text.ToString();
        cmd.Parameters.Add(DOB);

        SqlParameter curPwd = new SqlParameter("@CurPassword", SqlDbType.VarChar, 50);
        curPwd.Value = txtCurrentPassword.Text.ToString();
        cmd.Parameters.Add(curPwd);

        SqlParameter Password = new SqlParameter("@Password", SqlDbType.VarChar, 50);
        Password.Value = txtPassword.Text.ToString();
        cmd.Parameters.Add(Password);

        SqlParameter ConfirmPassword = new SqlParameter("@ConfirmPassword", SqlDbType.VarChar, 50);
        ConfirmPassword.Value = txtConfirmPassword.Text.ToString();
        cmd.Parameters.Add(ConfirmPassword);

        SqlParameter mobile = new SqlParameter("@Mobile", SqlDbType.BigInt);
        mobile.Value = txtMobile.Text.ToString();
        cmd.Parameters.Add(mobile);

        SqlParameter Address = new SqlParameter("@Address", SqlDbType.VarChar, 1000);
        Address.Value = txtAddress.Text.ToString();
        cmd.Parameters.Add(Address);

        SqlParameter City = new SqlParameter("@City", SqlDbType.VarChar, 50);
        City.Value = txtCity.Text.ToString();
        cmd.Parameters.Add(City);

        SqlParameter State = new SqlParameter("@State", SqlDbType.VarChar, 50);
        State.Value = txtState.Text.ToString();
        cmd.Parameters.Add(State);

        SqlParameter PIN = new SqlParameter("@PIN", SqlDbType.BigInt);
        PIN.Value = txtPIN.Text.ToString();
        cmd.Parameters.Add(PIN);

        SqlParameter Iam = new SqlParameter("@Iam", SqlDbType.VarChar, 50);
        Iam.Value = rbliam.Text.ToString();
        cmd.Parameters.Add(Iam);
        try
        {
            con.Open();
            int result = cmd.ExecuteNonQuery();
            if (result > 0)
                lblDisplay.Text = "Profile Updated";
            else
                lblDisplay.Text = "Please Check You Current Password";
        }
        catch (SqlException ex)
        {
            string errorMessage = "Error in updation";
            errorMessage += ex.Message;
            throw new Exception(errorMessage);
        }
        finally
        {
            con.Close();
        }





配置文件更新得很好。但是在更新配置文件后,我的文本框是空的。我希望在用户保存后显示更新的详细信息。

(原始文本 - 我希望显示之前的详细信息,并在修改和更新配置文件之后如何编写逻辑)。



请帮帮我。



Profile gets updated just fine. But my textboxes are empty after the profile is updated. I want to display updated details after user saves it.
(Original text - I want display previous details and after modify and update profile here how i write the logic).

Please help me.

推荐答案

Hai

更新成功后你需要获取数据形式数据库并显示在每个文本框中,这里只更新数据,而不是检索表单数据库。所以你需要使用选择查询来获取和显示在文本框中。



如果没有在文本框中显示数据,你需要避免页面刷新方法,我的意思是需要对所有文本框使用更新面板,所以只有页面刷新(点击服务器)。



填写完这些更新后,但我希望显示以前的详细信息,并在修改和更新配置文件后如何你试图问什么?



需要显示上次更新资料吗?



问候

Aravind
Hai
After update successfully u need get data form databse and show in each text boxes,here only u update the datas,not retrieve form database.So u need to use select query to get and show in text boxes.

If not show data in text box,u need to avoid page refresh method,i mean need to use update panel for all text boxes,so only if page refreshed(hit the server).

"after fill these updated properly but i want display previous details and after modify and update profile here how " what u try to ask ?

need to show last update profile ?

Regards
Aravind


您的ViewState是否正确PA是否已启用?



单击配置文件更新按钮以获取更新的详细信息后,您需要再次绑定控件。因此,基本上在按钮单击事件中,您将拥有代码来首先更新配置文件,然后编写代码以获取详细信息并将数据绑定到相应的控件。
Is ViewState on your page enabled?

You will need to bind your controls again after the profile update button is clicked to have the updated details. So basically in the button click event, you will have code to update the profile first and then write code to get details and bind the data to corresponding controls.


这篇关于更新asp.net网页的详细信息?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆