Click here to Skip to main content
15,912,578 members
Please Sign up or sign in to vote.
0.00/5 (No 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.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls.WebParts;
using System.Data.SqlClient;

public partial class Admin_Changepaswword : System.Web.UI.Page
{

   
        string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
        string str = null;
        SqlCommand com;
        byte up;
        


    protected void Button1_Click(object sender, EventArgs e)
    {
        SqlConnection con = new SqlConnection(strConnString);
            con.Open();
            str = "select * from registration ";
            com = new SqlCommand(str, con);
            SqlDataReader reader = com.ExecuteReader();

            while (reader.Read())
            {
                if (txtcnfpass.Text == reader["password"].ToString())
                {
                    up = 0;
                }
            }
            reader.Close();
            con.Close();
            if (up == 0)
            {
                con.Open();
                str = "update login set password="+txtnewpass.Text+" where id='1'";
                com = new SqlCommand(str, con);
                com.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
                com.Parameters["@Password"].Value = txtnewpass.Text;
               // com.ExecuteNonQuery();
                con.Close();
                Label1.Text = "Password changed Successfully";
            }
            else
            {
                Label1.Text = "Please enter correct Current password";
            }
        } 
    }
Posted
Updated 18-Mar-14 20:10pm
v2

1 solution

Change your code like this,
C#
con.Open();
str = "update login set password="+txtnewpass.Text+" where id='1'";
com = new SqlCommand(str, con);
//com.Parameters.Add(new SqlParameter("@Password", SqlDbType.VarChar, 50));
//com.Parameters["@Password"].Value = txtnewpass.Text;
com.ExecuteNonQuery();
con.Close();
 
Share this answer
 

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