Download as pdf or txt
Download as pdf or txt
You are on page 1of 19

Programmingknowledge.blogspot.

com C# & Sql Server2008


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

။ ႔ Database
(or) Project ႔ Default user name and password Login
။ ႔ ။ ႔
User Name and Password Login ။
႔ ႕
(၁) ။
႔ ႕

႕ ႔ ။
(၁) ႔ frmLogin ႔ frmMain Form
။ Project run ႔ LoginBox(frmLogin) ။ User Name and Password
Entery ID Card Box(frmMain) ။ ႔
Project Default User Name and Password ႔ ။ Project ႕ User
User Name and Password ႔ Login ။
႔ Project User Account User Account
User Account ႕ Password change Setting ႕
Function ႔ ။ ။ Setting Form
(frmSetting) Form(frmSetting) frmMain Form
linklabel ႔ ။

Linklabel(Setting…)
1. Tool Box linklabel frmMain Form ႔ ။
2. linklabel ႕ Properties ။
Control Name Text Font
linklabe1 linkSetting Setting... Zawgyi-One, 8.25pt
frmMain Form Setting… linklabel ႔ ။
linklabel ႕ frmSetting Form ။

frmSetting Form
႔ ႔ Create Account, Change Password and Delete Account
Function (3) Setting(frmSetting) Form ။
႔ Form ႕ UGI ႔ ။ C# ႕ Tool
။ ႔ Tool

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ TabControl Tool ႔ ။
.. ႔ Project Form ။

Fig.1 Fig.2
1. Fig.1 IDCheck_Tutorial( Project Name)  Add  Windows Form… Click
။ Fig.2 ။
2. Fig.2 Name: frmSetting.cs ႔ Add Click ။ ႔
Project frmSetting Form ႔ ။
Form ႔ UGI Form ႕ Properties ။
Control Name Text Font Maximizebox formBorderStyle StartPosition
linklabe1 linkSetting Setting... Zawgyi-One, 8.25pt False FixedDialog CenterScreen
Form ႕ Properties ႔ UGI ႔ ။
။ TabControl frmSetting Form ။ tabPage
။ tabPage ….
 Fig.3 tabPage R-Click  Add Tab ။

Fig.3 Fig.4
႔ (Create Account, Change Passord and Delete Account) Function
UGI ။ WebPage Account
Create ။ WebSite ႔ Account

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ frmSetting Form ႔ ႔
။ ။ ။

Fig.5 Fig.6

Fig.7
႔ frmSetting Form ႕ UGI ။ ႔
Coding tabPage Tool ႕ Properties

tabPage1-Control Name Text TabIntex PasswordChar
TextBox1 txtRegisterUN 0
TextBox2 txtRegisterPw 1 *
TextBox3 txtRegisterCPw 2 *
Button1 btnRegister Create 3

tabPage2-Control Name Text TabIntex PasswordChar


TextBox1 txtChangeUN 0
TextBox2 txtChangeOPw 1 *
TextBox3 txtChangeNPw 2 *
Button1 btnChange Change 3

tabPage3-Control Name Text TabIntex PasswordChar


TextBox1 txtDeleteUN 0
TextBox2 txtDeletePw 1 *
Button1 btnDelete Delete 2

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ tabPage ႕ Properties change ။ Label Page
႔ Label Properties
။ ႔ ။
။ ႔
႔ ႔ ။
။ .. ႔
႔ frmMain Form ႕ linklabe(Setting…) Setting(frmSetting) Form

frmSetting Form
႔ linklabel(Setting…) Setting
(frmSetting) Form ။ (၁) Login
Form ။ ႔ ။

1. frmMain Form linklabel(Setting…) D-Click ။ ႔ Coding
႔ ။
2. Coding ။
private void linkSetting_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{
this.Hide();
frmSetting showSetting = new frmSetting();
showSetting.ShowDialog();
}
။ Coding Login ။ …
 this.Hide(); frmMain Form Hide ( ႔) ။
 frmSetting showSetting = new frmSetting(); C# ႕ Method ။ frmSetting Form
showSetting Variable ။ showSetting
Variable Name ။
 showSetting.ShowDialog(); ႔ showSetting
Variable Show ( ႔) ႔ ။ ႔
Setting… linklabel frmMain Form frmSetting Form

႔ ။ ႔ Form (3)

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Form1 (frmLogin)

Form3 (frmSetting) Form2 (frmMain)


။ ႔ Project Form
(3) ။ Form1 User Name and Password Form2 frmMain
Form ။ ႔ User Account
Setting Form2 linklabel(Setting…)
Form3(frmSetting) Form ။ User Account UGI
။ ႔ ႔ SQL Database ႔

Insert UserName and Password Stored Procedure


႔ ႔ User Account ႔ SQL 2008
Stored Procedure ။ ႕ (၁) Login
Stored Procedure C# DataAdapter Add Qurery
။ C# SQL Server Stored Procedure ႕
။ ။ … ႔ SQL
Server Stored Procedure ….
1. Sql Server ။
2. Fig.8 IDCheck( Project ႕ Database Name) ProgrammabilityStored
ProceduresR-Click  New Stored Procedure... Click ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.8
3. Sql Coding Page ။ Page Command Line

CREATE PROCEDURE [dbo].[Insert_Login]
@Uname nvarchar(30),
@Pw nvarchar(20)
AS
BEGIN
Insert Into Tbl_Login(UserName,Password)
values(@Uname,@Pw)
END
Coding ႔ Sql Stored Procedure Syntax
။ ႔ ….
Create Procedure procedure_Name
@Variable1,
@Variable2,
@Variable….
As
Begin
Sql Command line
End
Syntax ႔ Coding ႔ ။
.. Procedure ႔ Tbl_Login
Table Record ။ ႔ Tbl_Login
(ID,UserName,Password) Field(3) ။ ID Identiry ႔ Record No
(၁) ႔ ။ ႔ Record UserName,
Password ။ ။
CREATE PROCEDURE [dbo].[Insert_Login]
@Uname nvarchar(30),
@Pw nvarchar(20)
Insert_Login Procedure ႕ Name ။ ။
@Uname , @Pw ႔ keyboard ႕ UserName and Password Field (2)
Variable ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Insert Into Tbl_Login(UserName,Password)
values(@Uname,@Pw)
Sql Table ႔ Record Insert ။ Tbl_Login
Table UserName and Password Field ႔ Keyboard ႕ Record
@Uname , @Pw ႔ ။ ႔
။ ႔ Database Insert_Login Procedure
႔ ။ ႕ ႔ ။

C# Insert_Login Procedure
SQL Server ႔ Insert_Login
Procedure C# ။ (၁)
Login Procedure ႔ ။ Screen Shoot
႔ ။
1. Fig.9 DsLogin.xsd(Login Table DataSet) 
Tbl_LoginTableAdapter R-Click Add Query… Click Fig.10 ။
2. Fig.10 Use existing stored procedure Next ။

Fig.9 Fig.10
3. Fig.11 Select the stored procedure…. (or)
Pocedure Name Next ။ Fig.12 ။
4. Fig.12 No value Selected Next ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.11 Fig.12
5. Fig.13 Next  Fig.14  Finish ။

Fig.13 Fig.14
6. ႔ Fig.15 ႔ TableAdapter ႔ Insert_Login
Stored Procedure ႔ ။

Fig.15
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ SQL C# Stored Procedure
႔ ႔ ။ ႔ C# Coding
႔ ။

C# Coding
C# Coding Login ။ NameSpace
႔ ။
using System.Data.SqlClient;
SQL Server ႔ Database Data C# Coding
NameSpace ။ SQL NameSpace

႔ Dataset TableAdapter Coding
႔ Variable ႔ ။
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter tblLogin = new
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter();
႔ DatasetFolder Tbl_LoginTableAdapter
tblLogin Variable ။ C#
Coding Database
tblLogin Variable ႔ Tbl_LoginTableAdapter
C# Coding ။
႔ ႔ Sql Connection On
။ ။
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
Command Line ။ ႔ Login Properties Setting.Setting
႔ connection conn Variable
။ Connection On ႔ Sql Server ႔ Data

။ Server ႔ connection Message Box ။
C# Coding Sql Server ႔ connection ။
႔ UserName and Password Account
Create Button Coding ။
private void btnRegister_Click(object sender, EventArgs e)
{
if (txtRegisterUN.Text != "")
{
if(txtRegisterPw.Text!="")
{
if (txtRegisterCPw.Text != "")
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
{
if (txtRegisterPw.Text == txtRegisterCPw.Text)
{
tblLogin.Insert_Login(txtRegisterUN.Text, txtRegisterPw.Text);
MessageBox.Show("Your Registion is Successful", "Register");
}
else
{
MessageBox.Show("Password Confirm Password ။", "Register");
txtRegisterCPw.Focus();
}
}
else
{
MessageBox.Show(" Confirm Password ။", "Register");
txtRegisterCPw.Focus();
}
}
else
{
MessageBox.Show(" Password ။", "Register");
txtRegisterPw.Focus();
}
}
else
{
MessageBox.Show(" User Name ။", "Register");
txtRegisterUN.Focus();
}
}
Coding Result Command Line ။
tblLogin.Insert_Login(txtRegisterUN.Text, txtRegisterPw.Text);
႔ Kenboard UserName(txtRegisterUN.Text) and Password
(txtRegisterPw.Text) Insert_Login Stored Procedure ႔ tblLogin ႔
႔ Variable Connection SQL Server UserName ,
Password Field ။
Command Line ႔ Project
။ if…else statement if…else statement
။ Nested if Statement ႔ ။ if connection
။ if connection ။ ႔ else
statement Result statement ။ if
statement ။ Programming
႔ ႔ ။
႔ textbox Focus command line ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
statement text Focus
။ Screen Shoot ။

Fig.16 Fig.17
 Fig.16 User Name, Password, Confirm Password Creat Button
။ Focus() User Name TextBox Selected
႔ ။
 Fig.17 User Name Create ။ Text
Selected Password textbox ။

Fig.18 Fig.19
 Fig.18 User Name ႔ Password Confirm Password
Create ။ Selected Confirm Password

 Fig.19 Text Field Password ႔ Confirm Password
။ Selected Confirm Password ။
 Fig.20 ႔ ႔ Text Field ။
Your Registion is Successful Message Box ။
 ႔ Sql ServerIDCheck( Project Database)Tbl_Login Table Fig.21
User Account ႔ ။ ႔ Project
႔ Login Account ႔ ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.20 Fig.21
႔ Project Login User Account ။ ႔
။ ႔ User Account ႔ Login ။

Fig.22 Fig.23
OK ။ ႔ ။
႔ Programming Language

႔ ႕ Language ႔ ႔
။ User Account
႔ Project ။
Screen Shoot ။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.24 Fig.25
Fig.(24,25) ႔ ။ ႔ Account
UserName and Password ႔ Success
။ ။
Project UserName and Password User
႔ User
။ …
။ ႕ ႔ ။

User Account UserName Sql Query


။ ႔ Account
Create User Name ႔ ။ ႕ Account ႕ User Name
Database ။ Your User Name is already exist. ( ႔) Invalid User Name
Message Box Try again ။ User Name Database
Password ႔ Confirm Password / Create ႔
။ OK… ႔ ႕
႕ ႔။
Name Check ႔ Sql Command line Query
။ Login Default UserName and Password
Database / ႔ ။

1. Fig.26 DsLogin.xsd ( ႕ Table ႕ Dataset) Tbl_LoginTableAdapter Add
Query ။ Fig.27 ။
2. Fig.27 Use SQL statement Selected Next ။ Fig.28 ။
3. Fig.28 ႔ User Name Return ႔ SELECT which
returns a single value Selected Next ။ SQL Command line Page

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.26 Fig.27

Fig.28 Fig.29
4. Fig.29 Sql Command line Next ။
SELECT COUNT(*) FROM Tbl_Login
Where UserName=@UName
႔ Keyboard ႕ User Name(@UName) ႔ Database
UserName Count=1
Count=0 Query ။ ။
5. Fig.30 Name Next Fig.31  Finish ။
Database Name ႔ CheckName ႔

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------

Fig.30 Fig.31
6. ႔ Tbl_LoginTableAdapter Fig.32 CheckName Query
႔ ။

Fig.32
႔ Database Name ႔ Keyboard ႕ Name ႔ Sql
Query ။ Query C# Coding

C# Coding CheckName Query UserName


C# & SQL Server 2008 Tutorial (၂) ႕
။ ။ SQL Coding C# Coding Basic
။ Programming ႔ ႔
႔ ။
႔ ႔ ႔
႔ ။ … ႔ ႕ ႔။

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ Create Button Coding ။
Coding ။
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();
}
}
else
{
MessageBox.Show(" Password ။", "Register");
txtRegisterPw.Focus();
}
}
else
{
MessageBox.Show(" User Name ။", "Register");
txtRegisterUN.Focus();
}
}
Coding ႔ ။
int chkName = int.Parse(tblLogin.CheckName(txtRegisterUN.Text).ToString());
if (chkName == 0)
{
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
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");
}
႔ Kenboard UserName(txtRegisterUN.Text) CheckName
Sql Query ႔ tblLogin ႔ ႔ Variable Connection
SQL Server UserName Field ႔
Count=1 Count=0 Return ။ Result
႔ chkName Variable ။ ႔ Result
။ Count=1(or) chkName=1 ႔ Database ။
UserName Your User Name is already exit in Database. Message Box
Count=0 (or) chkName=0 ႔ UserName
Database ။ Account ႔ ။ ..
tblLogin.Insert_Login(txtRegisterUN.Text, txtRegisterPw.Text);
Command Line Run ႔ Create User Account Database
။ Screen Shoot ။

Fig.33 Fig.34
 Fig.33 ႔ User Account ႕ UserName Datbase

 Fig.34 ႔ ႕ User Account ႕ UserName Database
။ Password ႔ Confirm Passowrd ႔ ။

Fig.35

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
 Fig.35 ႔ Kolin(456) User
Account Tbl_Login Table ႔ ။
႔ Account Create
Project ။
႕ frmSetting.cs ႕ Coding …….
using System;
using System.Collections.Generic;
using System.ComponentModel;
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();
}

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
{

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
MessageBox.Show("Password Confirm Password ။", "Register");
txtRegisterCPw.Focus();
}
}
else
{
MessageBox.Show(" Confirm Password ။", "Register");
txtRegisterCPw.Focus();
}
}
else
{
MessageBox.Show(" Password ။", "Register");
txtRegisterPw.Focus();
}
}
else
{
MessageBox.Show(" User Name ။", "Register");
txtRegisterUN.Focus();
}
}
}
}
႔ ။ ႔ (၂)
႔ ။ C# & SQL Server 2008 Tutorial (3)
User Account Delete User Account ႕ Password

C# and SQL Server 2008 (2 ။ ႔



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

Tay Zar Lin


Koyinmaung007@gmail.com
Programmingknowledge.blogspot.com

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

You might also like