0% found this document useful (0 votes)
50 views

C & SQL Server 2008 Tutorial - 3

This document discusses how to change a user account's password in C# and SQL Server 2008. It provides the following steps: 1. Create a query to update the password in the login table. 2. In the C# code, add a button click event to call the query. Check that the textboxes for username, old password, and new password are not empty, then show a confirmation message box. 3. If confirmed, call the query passing the username and new password. Otherwise, show a message that fields are empty. 4. The query updates the password field where the username matches the passed value. Additional explanations describe using message boxes, if/else statements, and calling the

Uploaded by

mthtar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
50 views

C & SQL Server 2008 Tutorial - 3

This document discusses how to change a user account's password in C# and SQL Server 2008. It provides the following steps: 1. Create a query to update the password in the login table. 2. In the C# code, add a button click event to call the query. Check that the textboxes for username, old password, and new password are not empty, then show a confirmation message box. 3. If confirmed, call the query passing the username and new password. Otherwise, show a message that fields are empty. 4. The query updates the password field where the username matches the passed value. Additional explanations describe using message boxes, if/else statements, and calling the

Uploaded by

mthtar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 16

Programmingknowledge.blogspot.

com C# & Sql Server2008


---------------------------------------------------------------------------------------------------------------------
C# & Sql Server 2008 Tutorial (3)

႔ ႔ ။
႕ (၃) ႔ ။ (၂)
Database (or) Project ႔ Login Account
။ ႔ ႔
Login Account Password ႔
Login Account ။
႔ ႕
(၁ ၂) ႔ ။ OK.. ႕ ႔…။

Change User Account’s Password


Login ႕ ႕
႔ ႔ ။
႔ ႕ Login Project IDCheck Database
၄ Login Tbl_Login Table ။
႔ C# UGI Record Sql ႕ IDCheck-Database
။ ႔ Tbl_Login
Table ။ Connection DataSet DataAdapter
႔ ။ Coding
။ ႕
။ ။ ႔..။

Account Password Change Sql Query


1. Fig.1 Tbl_LoginTableAdapter( ႕ Table ႕ TableAdapter)  R-Click Add
 Query…  Click ။

Fig.1
2. Fig.2 Use SQL statements Next ။ Fig.3 ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
3. ႔ Login Password Update
႔ ။ Fig.3 UPDATE Next ။ SQL Query
Page ။

Fig.2 Fig.3
4. ၄ Fig.4 Sql Query Next ။
Update Tbl_Login
Set UserName=@UserName, Password=@Password
Where UserName=@UserName
5. Fig.5 Next ။ User Account
႕ Password Change Query ႔ ChangeAccPw ႔ ။

Fig.4 Fig.5
6. Fig.6 Next ။
7. Fig.7 ႔ TablAdapter ChangeAccPw Sql Query
႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.6 Fig.7
႔ C# Coding ႔ ။ ႔
ChangeAccPw Query C#

Change User Account’s Password C# Coding


႕ SQL Server ႔ Connection
Command line ။ ႕ ႕
frmSetting.cs Form ႕ Command ႔ ။ ႔ (၂) SQl
Server ႔ Connection ။ ….
1. frmSetting Form ႕ TabControl tabPage2(Change Password Page)  Change Button D-
Click frmSetting.cs ႕ Coding ။
2. ၄ Change Button Command line Run ။
private void btnChange_Click(object sender, EventArgs e)
{
if (txtChangeUN.Text != "" & txtChangeOPw.Text !="" & txtChangeNPw.Text !="")
{
DialogResult result = MessageBox.Show("ဤ User Accont Password Change
။", "Change Pasword", MessageBoxButtons.YesNo, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
tblLogin.ChangeAccPw(txtChangeUN.Text, txtChangeNPw.Text);
MessageBox.Show("Success Your Change Password", "Change Password");
}
}
else
{

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
MessageBox.Show(" TextBox ႔ Record ။","Change
Password");
}
}
Change Button Run ႔ if statement ႔ ။
If(txtChangeUN.Text !=“” & txtChangeOPw.Text !=“” & txtChangeNPw.Text !=“”)
{
// Statement ႕
}
else
{
MessageBox.Show(" TextBox ႔ Record ။","Change Password");
}
႔ UserName Box, Old Password Box and New Password Box Keyboard
Record Change Button if statements Else
{…} Statement Message Statements if{…} Command
line ။ Fig.8 ။

Fig.8
႔ ။
DialogResult result = MessageBox.Show("ဤ User Accont Password Change ။",
"Change Pasword", MessageBoxButtons.YesNo, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
// Statement ႕
}
Command line MessageBox ႔
။ ႔ ။
.. MessageBoxButtons.YesNo User Message Box Yes and No
Buttons(2) ။ MessageBoxIcon.InformationUser ႔ Message
Information Icon ။
MessageBoxDefaultButton.Button1 Message Button1 Yes Button Dafault

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ Auto Selected ။ ႔ ႔ Message Mouse ႔
Yes Button Auto Selected Enter Key
Access ။

မူလ Login Record Fig.9


MessageBox ႔ Message
Yes (or) No Button User
။ User result
Variable ။ ႔ command line
if{…} Statement ႔ ။ ဤ User Account Password
Message User Yes (or) No Button ။ User
Yes ႔ If Statement ။ {..} Command Line
။ User No ႔ Password
Program ။
tblLogin.ChangeAccPw(txtChangeUN.Text, txtChangeNPw.Text);
MessageBox.Show("Success Your Change Password", "Change Password");
command line User Yes ႔ Cmd
။ SQL Database Connection ႔
tblLogin Variable ။ ႔ Change Password
ChangeAccPw SqlQuery keyboard ႔ txtChangeUN.Text
(UserName) ၄ UserName ႕ Password txtChangeNPw.Text(NewPassword)

။ ။ MessageBox
Attribute ။ … MessageBoxButtons
(AbortRetryIgnore, OK, OKCancel, RetryCancel, YesNo, YesNoCancel)
MessageBoxIcons (Asterisk, Error, Exclamation, Hand, Information, None, Question, Stop,
Warning) ။ Message Command

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ ႔ ႔ Login Account Tayza(221) Password (112)

Fig.10 ေျပာင္းလဲၿပီး Login Record


Message Box ႕ Yes Button ။ ႔ Database
Tayza Login Account Password 221 112 ႔
။ ႔ Project ႔ Tayza(221) Tayza(112) ႔ ႔
။ Fig ႔ ။

Project
Project Project
။ ႔ ႔ ။
႔ Change Password ။ ႔ Database
Login Account Password ႔
။ Screen Shoot ။

Fig.11 Fig.12
User Name: Tayza User Name: BoBo
Old Password: 010 Old Password: 111
New Password: 111 New Password: 221

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
 Fig.11 ။ ႔ User Name Database ၄
Account ႕ Password Database 112 ႔ Project Keyboard
Old Password 010 ။ Database Password ႔ Keyboard
႕ Old Password Filter
Old Password ChangeAccPw Sql Query User
Name New Password Database Old Password Change
။ ႔ Change User Account ႕
Password Change ၄ Password ႔ Project ႔
႔ ။
 Fig.12 ။ ႔ User Account Database
။ ႔ ႔ Filter Coding
Success ။ ႔
ChangeAccPw Sql Query User Name SQL Database ႔
။ / ။
။ ႔ Project ႕ ႔ ။
.. ။ ႕ (၁ ၂)

။ ။ ။
႔ (၁) Default UserName and Password ႔ CheckLogin Stored Procedure
။ Stored Procedure ႕ UserName and
Password Database / ။ Procedure ႔ Keyboard
႕ UserName ႔ Old Password Database / UserName and
Password ChangAccPw Query OldPassword
NewPassword ႔ Change ။ UserName and Password ( ႔)
Check… Your UserName and Password,Please! Message User Password
Login Account ႕ UserName and OldPassword
။ ။ Coding

private void btnChange_Click(object sender, EventArgs e)
{
if (txtChangeUN.Text != "" & txtChangeOPw.Text !="" & txtChangeNPw.Text !="")
{
DialogResult result = MessageBox.Show("ဤ User Accont Password Change ။",
"Change Pasword", MessageBoxButtons.YesNo, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
int checkLogin = int.Parse(tblLogin.CheckLogin(txtChangeUN.Text,
txtChangeOPw.Text).ToString());

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
if (checkLogin == 1)
{
tblLogin.ChangeAccPw(txtChangeUN.Text, txtChangeNPw.Text);
MessageBox.Show("Success Your Change Password", "Change Password");
}
else
{
MessageBox.Show("Check...Your UserName and Old Password.", "Change Password");
}
}
}
else
{
MessageBox.Show(" TextBox ႔ Record ။ ","Change Password");
}
}
႔ Coding ….
int checkLogin = int.Parse(tblLogin.CheckLogin(txtChangeUN.Text, txtChangeOPw.Text).ToString());
if (checkLogin == 1)
{
//ChangeAccPw Sql Query
}
else
{
MessageBox.Show("Check...Your UserName and Old Password.", "Change Password");
}
။ ။
CheckLogin Stored Procedure ႔ ႔ Keyboard UserName
႔ Old Password Database / ။ Record Database 1 ။
Record 0 ။ ႔ if statement ႔ Stored
Procedure ႕ Result 1( ) ႔ 0( ) checkLogin variable
။ if Statement ChangeAccPw Sql Query
႔ User Account New Password Update ။
။ Screen Shoot ။

Fig.13 Fig.14

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
 Fig.13 Database User Account Change Password
UserName Database Message ။
 Fig.14 User Name Database ႔ Old
Password ၄ User Name ႕ Password ႔ Old Password
Message ။

Fig.15 Fig.16
 Fig.15 ႔ Password ႔ User Name ႔ Old
Password Database ၄ User Account
႔ New Password ႔ Success

 Fig.16 ႔ Kolin(456) Account Kolin(222)
Result ။
Change User Account’s Password ႔ ။
Coding ႕ ႔ ။

User Account Delete


႕ User Account
Delete ႔ Project ႕ Setting ႕
။ ႔ Sql
Server ႔ Database Table ႔
Result Stored Procedure .. Sql Query

႔ C# Coding ။
Delete Account ႔ Sql Query
။ … ႔ ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Delete Account SQL Query

Fig.17 Fig.18
1. Fig.17 Tbl_LoginTableAdapter  R-Click  Add Query… Click ။
2. Fig.18 Use SQL statements Next ။

Fig.19 Fig.20
3. Fig.19 DELETE Next ။ Sql Qurey Page

4. Fig.20 command line Next ။
Delete From Tbl_Login
Where UserName=@UserName
5. Fig.21 Sql Query Name Next ။
User Account ႕ Query ႔ DeleteAccount

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
6. Fig.22 ႔ Next ။

Fig.21 Fig.22
7. ႔ ႕ Tbl_LoginTableAdapter Fig.23
DeleteAccount Query ။

Fig.23
႔ User Account Delete C# Coding ႔ ။
႔ DeleteAccount Query C#

Delete User Account C# Coding


Change User Account’s Password ႔ ။
frmSetting.cs Coding ႔ SQL Server ႔ Connection
။ ….
1. frmSetting Form ႕ TabControl tabPage3(Delete Account)  Delete Button D-Click
frmSetting.cs ႕ Coding ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
2. ၄ Delete Button Command line Run ။
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtDeleteUN.Text != "" & txtDeletePw.Text != "")
{
DialogResult result = MessageBox.Show("ဤ User Accont Delete ။",
"Delete Account", MessageBoxButtons.YesNo, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
int delAccount = int.Parse(tblLogin.CheckLogin(txtDeleteUN.Text, txtDeletePw.Text).ToString());
if (delAccount == 1)
{
tblLogin.DeleteAccount(txtDeleteUN.Text);
MessageBox.Show("Delete Complete","Delete Account");
}
else
{
MessageBox.Show("Recheck... Your Login Record.", "Delete Account");
}
}
}
else
{
MessageBox.Show(" Delete Account ၏ UserName and Password
TextBox ႔ ။","Delete Account");
}
}
Delete Button Run ႔ if statement Fig.24 ႕ Result
႔ UserName and Password ။

Fig.24 Fig.25

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
User Account / User Choose
။ User Yes( ) … ႔ ႕ Loging Account Database
/ CheckLogin Stored Procedure ႔ ။ 1 0 ။1
႔ Login Account ႔ ။ DeleteAccount Sql Query
Delete Complete Fig.27 Message ။

Fig.26 Fig.27
0( ) ႔ Record UserName Password
႔ ႕ Login Account Database
။ Fig.(25,26) Recheck.. Your Login Record.

Fig.28
Fig.28 ႔ Login Account(Kolin-222) Delete ။ Coding

။ ႔ ။
႔ ႕ ႔
frmSetting.cs Form ႕ (Register, Change Password, Delete Account ) Codding
။ ။
using System;
using System.Collections.Generic;
using System.ComponentModel;

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace IDCheck_Tutorial
{
public partial class frmSetting : Form
{
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter tblLogin = new
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter();
public frmSetting()
{
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
InitializeComponent();
}
Register
private void btnRegister_Click(object sender, EventArgs e)
{
if (txtRegisterUN.Text != "")
{
if(txtRegisterPw.Text!="")
{
if (txtRegisterCPw.Text != "")
{
if (txtRegisterPw.Text == txtRegisterCPw.Text)
{
int chkName = int.Parse(tblLogin.CheckName(txtRegisterUN.Text).ToString());
if (chkName == 0)
{
tblLogin.Insert_Login(txtRegisterUN.Text, txtRegisterPw.Text);
MessageBox.Show("Your Registion is Successful", "Register");
}
else
{
MessageBox.Show("Your User Name is already exit in Database.","Register");
}
}
else
{
MessageBox.Show("Password Confirm Password ။", "Register");
txtRegisterCPw.Focus();
}
}
else
{
MessageBox.Show(" Confirm Password ။", "Register");
txtRegisterCPw.Focus();
}
}

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
else
{
MessageBox.Show(" Password ။", "Register");
txtRegisterPw.Focus();
}
}
else
{
MessageBox.Show(" User Name ။", "Register");
txtRegisterUN.Focus();
}
}
Change Password
private void btnChange_Click(object sender, EventArgs e)
{
if (txtChangeUN.Text != "" & txtChangeOPw.Text !="" & txtChangeNPw.Text !="")
{
DialogResult result = MessageBox.Show("ဤ User Accont Password Change
။", "Change Pasword", MessageBoxButtons.YesNo, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
int checkLogin = int.Parse(tblLogin.CheckLogin(txtChangeUN.Text,
txtChangeOPw.Text).ToString());
if (checkLogin == 1)
{
tblLogin.ChangeAccPw(txtChangeUN.Text, txtChangeNPw.Text);
MessageBox.Show("Success Your Change Password", "Change Password");
}
else
{
MessageBox.Show("Check...Your UserName and Old Password.", "Change Password");
}
}
}
else
{
MessageBox.Show(" TextBox ႔ Record ။ ","Change Password");
}
}
Delete Account
private void btnDelete_Click(object sender, EventArgs e)
{
if (txtDeleteUN.Text != "" & txtDeletePw.Text != "")
{
DialogResult result = MessageBox.Show("ဤ User Accont Delete ။",
"Delete Account", MessageBoxButtons.YesNo, MessageBoxIcon.Information,
MessageBoxDefaultButton.Button1);
if (result == DialogResult.Yes)
{
int delAccount = int.Parse(tblLogin.CheckLogin(txtDeleteUN.Text, txtDeletePw.Text).ToString());
if (delAccount == 1)
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
{
tblLogin.DeleteAccount(txtDeleteUN.Text);
MessageBox.Show("Delete Complete","Delete Account");
}
else
{
MessageBox.Show("Recheck... Your Login Record.", "Delete Account");
}
}
}
else
{
MessageBox.Show(" Delete Account ၏ UserName and Password
TextBox ႔ ။","Delete Account");
}
}

}
}
႔ ႔ Project Default
UserName and Password ႔ UserName and Password ႔
႔ SQL & C# Coding ။ ႔
Login Account Password Account
Coding ။ ႔
Programming Language ။
။ ။ ႔ …..

C# and SQL Server 2008 (3 ။ ႔



႔ ။
႔ ။
႔ ၏ ႔… ႔၏
႔… ။

Tay Zar Lin


[email protected]
Programmingknowledge.blogspot.com

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။

You might also like