i want to create change password form is there any code pls send me [Resolved]

Posted by Sudheep.grandhe under C# on 12/16/2011 | Points: 10 | Views : 37247 | Status : [Member] | Replies : 11
hi
i want changepassword code using c#.
I created login form in that form user id ,password the person login in to page if he wants to change password,if he click the change password link it opens then he enter old password new and confrom .



thanking you,

Best,
Sudheep.



Responses

Posted by: Sksingh on: 12/19/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi,

Please check out you have missed out executenonquery statement .

if (count > 0) 

{
querystring ="update tbl_login set password='" +txtNewpassword .Text .Trim ()+"' where username='" +txtusername .Text .Trim ()+"'";
ExecuteNonQuery(querystring);
MessageBox .Show ("Password has been changed successfully","Information",MessageBoxButtons .OK ,MessageBoxIcon.Information );
}


Regards,
Sunil

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Varung on: 12/16/2011 [Member] Starter | Points: 25

Up
0
Down
update the new pwd into corresponding table.....

in the click event of change pwd
write

update <table name> set password=<new pwd textbox value> where loginid=<id of the user>

G.Varun

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Thanks replying to me.can you send step by step procedure.it will helpfull for me.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksingh on: 12/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Please check attached sample code.
Its not working application but will give u clear idea about how to implement your logic here.
Change connectionstring with your proper connection string as well as check your query whereever used.
 Download source file

Regards,
Sunil

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

i want to Delete a seleted row from a DataGrid using c# windows application.for that i have two tables tbl_report1,tbl_report2

tbl_report1 columns:invoiceno(FK),particulars,quantity,perprice,amount,compname,invoicedate,ondate,orderno,invoiceid.

tbl_report2 columns:compname,compaddress,invoiceno(PK),orderno,ondate,invoicedate,amountstatus,netamount,netvat,tamount

from above two tables i have to design a query for delete and update.based on invoiceno.please do the needful.

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sksingh on: 12/16/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

Try below code

private void DeleteRecords()

{
SqlTransaction tran = null;
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd;
int invoiceno = 2;//TODO: get invoiceno from selected grid row
try
{
if (con.State == ConnectionState.Closed)
con.Open();
tran = con.BeginTransaction();
cmd = new SqlCommand("delete from tbl_report1 where invoiceno =" + invoiceno + "", con, tran);
cmd.ExecuteNonQuery();

cmd = new SqlCommand("delete from tbl_report2 where invoiceno =" + invoiceno + "", con, tran);
cmd.ExecuteNonQuery();

//Commit Transaction
tran.Commit();

}
catch
{
//Rollback
tran.Rollback();
}
finally
{
if (con.State == ConnectionState.Open)
con.Close();
}
}


Change invoiceno as per your requirement.

Regards,
Sunil

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/17/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

it shows the following error.Error:Object reference not set to an instance of an object.

public int ExecuteScalar(string Querystring)
{
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd = new SqlCommand(Querystring, con);
con.Open();
SqlDataAdapter adp = new SqlDataAdapter(cmd);
return (int)cmd.ExecuteScalar();
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/19/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

here is the update_click event code.please find it.

private void btnupdate_Click(object sender, EventArgs e)
{
string querystring = string.Empty;
if (!Validation())
return;
if (txtNewpassword.Text.Trim() != txtreenternewpassword.Text.Trim())
{
MessageBox.Show("Re-Entered Password does match with new password", "Information", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
else
{
querystring ="update tbl_login set username='" +txtusername .Text .Trim ()+"' where password='"+txtoldpassword .Text .Trim ()+"'";
int count= ExecuteNonQuery (querystring );
if (count > 0)
{
querystring ="update tbl_login set password='" +txtNewpassword .Text .Trim ()+"' where username='" +txtusername .Text .Trim ()+"'";
MessageBox .Show ("Password has been changed successfully","Information",MessageBoxButtons .OK ,MessageBoxIcon.Information );
}
}
txtusername.Text = "";
txtoldpassword.Text = "";
txtNewpassword.Text = "";
txtreenternewpassword.Text = "";
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/19/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

here is the delete code.please find it.
private void btn_delete_Click_1(object sender, EventArgs e)
{
SqlTransaction tran = null;
SqlConnection con = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");
SqlCommand cmd;
int invoiceno = 1;
try
{
if (con.State == ConnectionState.Closed)
con.Open();
tran = con.BeginTransaction();
cmd = new SqlCommand("delete from tbl_report2 where invoiceno =" + invoiceno + "", con, tran);
cmd.ExecuteNonQuery();
tran.Commit();
}
catch
{
tran.Rollback();
}
finally
{
if (con.State == ConnectionState.Open)
{
con.Close();
}
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Sudheep.grandhe on: 12/19/2011 [Member] Starter | Points: 25

Up
0
Down
Hi,

i am trying to add the record it shows the error.Error4'marsweb.imageimpacts.NewInvoice.sqlConnection' is a 'field' but is used like a 'type'.please give me the code for add records to db and update and delete.please do the needful.

private void btn_add_Click(object sender, EventArgs e)
{
DBConnection db = new DBConnection();
SqlConnection con = db.opencon();
SqlCommand cmd = new SqlCommand("insert into tbl_report1 (invoiceno,particulars,quantity,perprice,amount,orderno,compname,invoicedate,ondate,invoiceid)values(@invoiceno,@particulars,@quantity,@perprice,@amount,@orderno,@compname,@invoicedate,@ondate,@invoiceid)", con);
cmd.Parameters.AddWithValue("@invoiceno", txt_invoiceno.Text);
cmd.Parameters.AddWithValue("@particulars", cmb_particulars.Text);
cmd.Parameters.AddWithValue("@quantity", txt_quantity.Text);
cmd.Parameters.AddWithValue("@perprice", txt_perprice.Text);
cmd.Parameters.AddWithValue("@amount", txt_amount.Text);
cmd.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd.Parameters.AddWithValue("@compname", cmb_companyname.Text);
if (txt_invoicedate.Text != null && txt_invoicedate.Text.Trim() != "")
{
cmd.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
}
else
{
cmd.Parameters.AddWithValue("@invoicedate", DBNull.Value);
}
if (txt_ondate.Text != null && txt_ondate.Text.Trim() != "")
{
cmd.Parameters.AddWithValue("@ondate", txt_ondate.Text);
}
else
{
cmd.Parameters.AddWithValue("@ondate", DBNull.Value);
}
sqlConnection conn = new SqlConnection("data source=mars-104;initial catalog=Sudheeptest;integrated security=true");//error shows here
SqlCommand cmd1 = new SqlCommand("insert into tbl_report2(compname,compaddress,invoiceno,orderno,invoicedate,ondate,amountstatus)values(@compname,@compaddress,@invoiceno,@orderno,@invoicedate,@ondate,@amountstatus)", conn);
cmd1.Parameters.AddWithValue("@compname", cmb_companyname.Text);
cmd1.Parameters.AddWithValue("@compaddress", txt_customeraddress.Text);
cmd1.Parameters.AddWithValue("@invoiceno", txt_invoiceno.Text);
cmd1.Parameters.AddWithValue("@orderno", txt_orderno.Text);
cmd1.Parameters.AddWithValue("@invoicedate", txt_invoicedate.Text);
cmd1.Parameters.AddWithValue("@ondate", txt_ondate.Text);
cmd1.Parameters.AddWithValue("@amountstatus", rb_paid.Checked);
cmd1.Parameters.AddWithValue("@amountstatus", rb_unpaid.Checked);
conn.open();
cmd1.ExecuteNonQuery();

cmd.Parameters.AddWithValue("@invoiceid", txt_invoiceno.Text);
SqlDataAdapter da = new SqlDataAdapter(cmd);
if (con.State == ConnectionState.Closed)
{
con.Open();
}
cmd.ExecuteNonQuery();
con.Close();
txt_quantity.Text = "";
txt_perprice.Text = "";
txt_amount.Text = "";
netamount();
loadparticularsdata();
vatamount();
griddisplay();
}

Best,
Sudheep.

Sudheep.grandhe, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response