SQL Server Tutorial Myanmar
SQL Server Tutorial Myanmar
pdf
C & SQL Server 2008 Tutorial_2.pdf
C & SQL Server 2008 Tutorial_3.pdf
C & SQL Server 2008 Tutorial_4.pdf
C & SQL Server 2008 Tutorial_5.pdf
Database Backup & Restore in SQL Server 2008.pdf
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Login Database by C# & Sql Server 2008 Tutorial_(1)
Login Database
Fig.1
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
C# Page Form ႔ ။ ႔ Form
႕ Login Data User Interface ႔
႔ Form ။
။
႔ C# ႕ Form
Toolbox, Solution Explorer ႔ Properties box ႔ ။ Toolbox ႔
botton Solution Explorer ႔
Project File ။ Porperties box
႔ Form
။
။
႔ Form Button Form ႕ Properties
။
Control Name Text Font Maximizebox formBorderStyle StartPosition
Form1 frmLogin Login Zawgyi-One, 8.25pt False FixedDialog CenterScreen
႔ Form ။၄ ႕ Result
။
Fig.2
Name: Form Coding ၄
႔ Form ။ Text: Form box ႕ Title
။ Font: Form Font ႔ Zawgyi-One ႔
။ Maximizebox: Maximize
။ ႔ ႔ False ႔ Max ။
FormBorderStyle: FixedDialog ႔ ႕ Form /
Fixed ။ StartPosition: CenterScreen
႔ Program Run Result From Box Screen ႕
႔ ။ Form ႕ Icon Properties box ႕ Icon
။ ။
။ ႔ Login ႕ TextBox(2) Button ႔ ႕
Properties ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Control Name Text TabIndex PasswordChar
TextBox1 txtUserName 0
TextBox2 txtPassword 1 *
Button1 btnLogin Login 2
Label1 User Name:
Label2 Password:
Fig.3
Fig.3 TextBox, Label and Button ႔ ႕ Properties
။ Name ႔ Coding
႔ ႔ ။ keyword ႔
။ Text ႕
User ။
TabIntex ႔ Tab Key
႔ ။ Text Intex 0
Intex key ။ Login Box
Intex 0 User Name TextBox Selected
႔ User Name ႔ Tab ႔ Intex 1 Password TextBox
Selected ။ TabIntex Intex key
။ TabIntex ႔
႔ ႔ ။
႔ ႕ ။ Beginner
႔ ။
႔ ။
PasswordChar (*) ႔ Password TextBox
႕ Password (*) ။ Fig.3 Password
TextBox ။ (*) key
Character (@,#,$,&,….) ။
PictureBox ႔ Login Box User
႔ ။ ႕ ႕ ႔
။ ။ (၁) Microsoft
Visual Studio 2008 ႕ C# User Interface ႔ ။
႕ ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
၂. Microsoft Sql Server 2008 Database
႔ ႔ Microsoft SQL Server 2008 Database
႔ ႕ Table Store Procedure ။ SQL Server
Database Table Sql Command line ႔ Window System ႔
။ Sql Command Line ႔ programmingknowledge.blogspot.com
႔ Topic ႔ ။ Sql command
line Window System Database, Table,…
။
Database
႔ Project Database ။
Sql command line …
Create Database IDCheck;
Sql command line New Query command Run ။
Window System ….
1. Fig.4 Database Folder R-Click New Database ။
Fig.5 ။
Fig.4 Fig.5
2. Database name: Project ၏ Database Name ။
IDCheck ႔ ။
3. Database Files: Path Project ၏ Database
။
4. OK ။
႔ Sql Server ႕ Database Folder IDCheck Database
႔ ။ Sql command line Window System
Result ။ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Table
႔ ႔ Database Login Table
IDCheck Databse ႔ ။ Sql command line …
CREATE TABLE Tbl_Login
(
ID int PRINARY KEY IDENTITY(1,1) NOT NULL,
UserName nvarchar(30) NULL,
Password nvarchar(20) NULL
);
(or)
Window System ႔ …
Fig.6 Fig.7
1. Fig.6 Table Folder R-Click New Table… ။ Fig.7
Column Name, Data Type & Allow Null Fig.7 ။
2. ID Primary Key ID Row R-Click Primary Key ။
3. ၄ ID Column Click Column Properties Identity Specification
Fig.8 ။ Record
ID No ။
4. Save ။ Login ႔
Tbl_Login ႔ ။
Fig.8
။ ။ Identity int Data Type Count Data Type ႔ ။
UserName ႔ Password nvarchar() ႔ UserName ႔ Password
႕ record Unicode ႔ ။
႔ ႕ IDCheck Database Tbl_Login ID, UserName, Password Column
Field Table ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Table ႔ Record
႔ ႕ UserName and Password ႔ Project
။ Default ႔ ႔ UserName and Password ။
Login ႔ Tbl_Login Table ႔ Default ႕
UserName and Password Record ။ .. Record
။ Sql command line ….
Insert Into Tbl_Login( ‘Admin’, ‘123’);
(or)
Window System ႔ ….
Fig.9 Fig.10
1. Fig.9 Sql Server Database IDCheck( Database Name) Tbl_Login( Table
Name) R-Click Edit Top 200 Rows Click ။ Fig.10 ။
2. Fig.10 UserName and Password Enter ။ ႔ ID
UserName and Password ႔ Enter
Auto (1) ႔ ။ ႔
Table ID Identity ႔ ။
3. ႔ Default ႔ ႕ User Naem and Password
Save ႔ ။ Save Fig.10
Execute SQL Button Click Save ။
႔ Table ႔ Record ။
႔ ႔ Default ႕ UserName and Password
။ Admin Account
User Account User Account
။ ႔ (၃) ႔။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ ႔
။ ႕ ႕
႔ ။ … ႔ ႕ ႔။
Database Connection
Fig.13 Fig.11
Fig.12
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
2. Fig.12 Name: database connection
။ IDCheckConString ။
Type: ႔ Scope: ။ Value: Click
Fig.13 ။
3. Fig.13 Data Source: Change Microsoft Sql Server(SqlClient) ။
Server Name: ။ Log on the server:
Use Windows Authentication ။ Sql Server Windows System
႔ ။ ႔ ႔
Server ႔ Name and Password Use Sql Server
Authentication ။ Select or enter the database name:
(၂) ႔ Database IDCheck
။
4. ႔ Sql Server IDCheck Database ႔ ႕
။ ႔ /
႔ Test Connection Button ။ Fig.13
Message Box Error
Message Box ။
5. OK ။
DataSet
Sql Server Project Dataset
။ Dataset Sql server
Database C# ႕ UGI ။
Fig.14 Fig.15
Table Dataset ။ ႕
Dataset Table ၄ Dataset ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ ႕
Error Trip Table Dataset
႔ ။ .. Database Table ။ ၄
Table ႔ record Insert, Update and Delete ။
Table Error ၄ Table ႔ Dataset
Table ႕ record
။ Dataset Table
Error
။ Dataset ႔ ႔
႕ ႔ ။
1. ႔ Dataset Folder ။ ႔
Dataset ႔ ။
Folder ႔ ။ .. Dataset Folder
႔ Fig.14 IDCheck_Tutorial( project name) R-Click
Add New Folder ႔ ။ ႔ project Folder
။ ။ Dataset
Folder ႔ DatasetFolder ႔ ။
2. Dataset ။ Fig.15
Folder R-Click Add New Items… ႔ ။ Fig.16 ။
Fig.16
3. Fig.16 Dataste Name: Add Click ။
Login Dataset ႔ DsLogin.xsd ႔ ။
႔ DsLogin.xsd Dataset Page ။ Dataset
IDCheck Database Tbl_Login Table ႔ ။ ႔။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Table Adapter ( ႔) Dataset ႔ Table
႔ DsLogin Dataset Tbl_Login
Table ။ ။ ႔
႔ ။ ႔ ႔
။ … ႔..။
Fig.17 Fig.18
1. Fig.17 Dataset Page R-Click Add TableAdapter... Click
။ Fig.18 ။
2. Which data connection should your application use to connect to the database ?
Database Connection (Fig.12) ႔ Connection Name
Next ။ Fig.19 ။
Fig.19 Fig.20
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
3. Use SQL statements Selected Next ။ Sql command line
Fig.20 ။
4. Fig.20 Select * From Tbl_Login ႔ command line Next ။
Tbl_Login Table Column Field ႔
။ Fig.21 ။
Fig.21 Fig.22
5. Fig.21 Next Fig.22 Finish ။
Fig.23
Fig.23 Tbl_Login Table ႕ Table Adapter ။
႔ Sql Procedure ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.24 Fig.25
1. Fig.24 Tbl_LoginTableAdapter R-Click Add Query.. ။ Fig.25 ။
2. Fig.25 Create new stored procedure Selected Next ။
Fig.26 Fig.27
3. ႔ ႔ Database ႔ Login Record /
Fig.26 SELECT which returns a single value Selected Next
။ Sql procedure ႔ Fig.27 ။
4. Command line Next ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Select Count(*) From Tbl_Login
Where UserName=@Name And Password=@Pw;
႔ Where ႔ ။ Where Table UserName = @
႔ ႕ UserName ။ ႔ UserName Database Table
႔ ။ Count ။ Count=1
Success ။ Count=0 UserName - Project ႔ ။ Password
။ ႔ ။ And connection
႔ ။ Error ။
Fig.28 Fig.29
5. Fig.28 What do you want to name the new stored procedure ?
Next Fig.29 Next ။
Fig.30 Fig.31
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
6. Fig.30 Finish ။ Name and Password ႔ CheckLogin
Stored Procedure ႔ Tbl_LoginTableAdapter ။
႔ (၃) Sql Server ႔ C# ႔ Connection
(၃) ႔ ႔ ။ ။ C#
coding Sql command line ႔ ႔ ။
႔ command line ႔ Sql C#
coding ႔
႔ ။
။ ႔ ။
။
၄.C# Coding
႔ ။
Login by Database ႕ ။
C# Coding ။ Namespace ႔ ႔။
using System.Data.SqlClient;
႔ ႔ SQL Server ႔ Sql command line C# Coding
Namespacea ။
႔ Dataset TableAdapter coding
variable ။
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter tblLogin = new
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter();
႔ DatasetFolder Tbl_LoginTableAdapter
tblLogin Variable ။
႔ Coding Database ႔
tblLogin Variable ႔ Tbl_LoginTableAdapter
C# Coding ။
TableAdapter tblLogin
႔ Sql Server ႔ connection ။
။
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
command line ။ Sql Server ႔ conn variable
။ Coding (Fig.11,12,13) ႔
။ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
C# Coding Sql Server ႔ Connection ။ ႔ ႕
Login ႕ UserName and Password / ႕ Login Button Coding ႔ ။
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUserName.Text != "" & txtPassword.Text != "")
{
int chkLogin = int.Parse(tblLogin.CheckLogin(txtUserName.Text, txtPassword.Text).ToString());
if (chkLogin == 1)
{
MessageBox.Show("Your Login is Successful", "Login");
}
else
{
MessageBox.Show("Incorrect User Name and Password, please Try again!!","Login");
}
}
else
{
MessageBox.Show("Enter User Name and Password in TextBox","Login");
}
}
If Statement ႔ if (txtUserName.Text != "" & txtPassword.Text != "")
။ IF statement {…} else{…}
Enter User Name and Password in TextBox Message Box ။
int chkLogin = int.Parse(tblLogin.CheckLogin(txtUserName.Text, txtPassword.Text).ToString());
command line ႔ keyboard UserName(txtUserName.Text)
Password(txtPassword.Text) Database / CheckLogin Stored Procedure
။ (Count=1 or Count=0) ႔ Procedure
Record Database 1 0 ။ C# Data
String type ႔ ။ ႔ If(chkLogin==1) int Type ႔
int.Parse() ႔ CheckLogin Procedure Resurt int Type
chkLogin variable ။ ႔ ။
if (chkLogin == 1)
{
MessageBox.Show("Your Login is Successful", "Login");
}
else
{
MessageBox.Show("Incorrect User Name and Password, please Try again!!","Login");
}
command line ႔ int Type chkLogin
variable if statement ႔ ။ Result 1
႔ UserName and Password Record Database ။
Your Login is Successful Message Box ႔ if (chkLogin == 1)
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Result 0 else statement Incorrect User Name and
Password, please Try again!! Message Box ။ Coding
႔ ။ ႔ Login Project ႕
Screen Shoot ႔ ။
Fig.32 Fig.33
Fig.32 ႔ User Name: and Password: Login Button
Click ။ Fig.33 User Name: Password:
။
Fig.34
Fig.34 ႔ keyboard UserName and Password Login
႔ Default UserName and Password ႔ Success
။ ႔ ႔
။
Login Project 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
{
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
public partial class frmLogin : Form
{
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter tblLogin = new
DataSetFolder.DsLoginTableAdapters.Tbl_LoginTableAdapter();
public frmLogin()
{
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
InitializeComponent();
}
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.35 Fig.36
3. ႔ ( )၏ Data Database ႔
Form Frame ။
Fig.37
frmMain Form ႕ Form Properties
။ Login frmMain Form
႔ ။ frmMain Form ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Control Name Text Font Maximizebox formBorderStyle StartPosition
Form2 FrmMain Entry ID Card Zawgyi-One, 8.25pt False FixedDialog CenterScreen
Properties ။ frmLogin.cs
။ Name: Coding ႔ ႔
။ … ႔ frmMain.cs Coding ။
private void btnLogin_Click(object sender, EventArgs e)
{
if (txtUserName.Text != "" & txtPassword.Text != "")
{
int chkLogin = int.Parse(tblLogin.CheckLogin(txtUserName.Text, txtPassword.Text).ToString());
if (chkLogin == 1)
{
this.Hide();
frmMain ShowMain = new frmMain();
ShowMain.ShowDialog();
}
else
{
MessageBox.Show("Incorrect UserName and Password, please Try again!!","Login");
}
}
else
{
MessageBox.Show("Enter User Name and Password in TextBox","Login");
}
}
Coding ႔ ။ login
Message Box ။
this.Hide();
frmMain ShowMain = new frmMain();
ShowMain.ShowDialog();
this.Hide() ႔ frmLogin.cs Hide ႔
။ command line Login frmLogin Form ။
frmMain ShowMain = new frmMain(); C# ႕ Method ။ ႔ frmMain
႔ Main Page ShowMain Variable ။
ShowMain.ShowDialog(); ႔ command line ShowMain
Variable Screen frmMain Form ။
႔ ။
Fig.38
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
User Name = Admin
Password = 123
Fig.39
Fig.38 User Name and Password Fig.39 ။
Incorrect UserName and Password, please Try again!! ။ ႔
။
႔ User Account
User Account ႕ Password Change ။
႔ ႔ ႔ ႔ ။
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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)
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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 ServerIDCheck( 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
။ …
။ ႕ ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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();
}
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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
။
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
C# & Sql Server 2008 Tutorial (3)
႔ ႔ ။
႕ (၃) ႔ ။ (၂)
Database (or) Project ႔ Login Account
။ ႔ ႔
Login Account Password ႔
Login Account ။
႔ ႕
(၁ ၂) ႔ ။ OK.. ႕ ႔…။
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#
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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.InformationUser ႔ 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 ။
။ ။ 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)
။
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 ႕ ႔ ။
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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#
။
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 ။
။ ။ ႔ …..
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
C# & Sql Server 2008 Tutorial (4)
။ ႔ ႔ C# & SQL
Database Project ႔ Login Project Setting
။ Command line ႔
႔ ႔ ႔ ႔ ။ (၄)
Login Success ႔ ႕ Project ႕ Main Page UGI SQL Server
Record Table ႔
။
႔ ႔ ႕ Project ႕ Final Goal
႔ ။ ႔ ႔ Tutorials ( ႔)
Data Database
Update Record Delete Database
Record Data ( ႔) Search Engine
႔ ႔ ။ ႔
(၄) Project (၆ ႔ ၇) ႔ ။
႔ ႔
။
။ ႕ ႔
။ ႔… ။
႔ Main Page frmMain Form ႕ UGI ။
Record Database ႔ Fig.1 ။
Fig.1
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
frmMain Form (၁) ႔ Form
။ Tool ႕ Fig.1
။ ႔ MaskedTextBox(2) ႔ ComboBox(1)
႔ ။ ၄ ႔ ႕ Function ။
MaskedTextBox(2) Date ။ ႔ ႕ Function ….
MaskTextBox Fig.1
1. MaskedTextBox Selected Properties Box Mask Click
။ Input Mask Box ။
MaskTextBox Fig.2
2. ၄ Data Format ။
Short date Format ။
MaskedTextBox ႔ ။
3. ReadyMade ။ Custom
Mask: ။ Preview:
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
MaskedTextBox(2) ႔
ComboBox ။
ComboBox Fig.1
1. ComboBox Selected Properties Items
Click ။ ႔ Items
String Collection Editor Box ။
2. ၄ String Collection Editor Box Items
OK ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
TextBox4 txtFatherName 4
MaskedTextBox2 txtBirthDay 5
TextBox5 txtReligion / 6
TextBox6 txtHeight 7
ComboBox1 cbBloodType 8
TextBox7 txtWork 9
TextBox8 txtMark 10
TextBox9 txtAddress 11
PictureBox1 picView -
DataGridView1 DgvRecord -
Tbl_Main Table
SQL Server Table ႕ Windows System
႔ ႔ New
Query Command line Table ။
။
Fig.2
1. Fig.2 IDCheck( Project ႕ Database Name) R-Click New Query
Click ။ ႔ Sql command line Page
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
2. command line ၄ Page Execute Button
Save ။
Create Table Tbl_Main
(
NoId int identity primary key Not Null,
No nvarchar(15) Null,
ID nvarchar(20) Null,
IssueDate nvarchar(15) Null,
Name nvarchar(20) Null,
FatherName nvarchar(20) Null,
BirthDay nvarchar(15) Null,
Religion nvarchar(20) Null,
Hight nvarchar(15) Null,
BloodType nvarchar(5) Null,
Work nvarchar(50) Null,
Mark nvarchar(50) Null,
Adress nvarchar(100) Null,
Picture varbinary (max) Null
)
3. Fig. 3 ႔ IDCheck Database Tbl_Main Table
႔ ။
Fig.3
႔ ႔ ( ႔) Data
႔ Tbl_Main Table ။ … ႔ Record
႔ Tabl Data ႔ ႔
႔ ။ ။ ႕ ႔ Stored
Procedure ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.4
1. Fig.4 IDCheck Programmability Stored Procedures R-Click New Stored
Procedure.. Click ။ ႔ Stored Procedure
႔ Page ။
2. Sql Command line ၄ Page Execute Button
Save ။
CREATE PROCEDURE [dbo].[Insert_Main]
@No nvarchar(15),
@ID nvarchar(20),
@IsDate nvarchar(15),
Variable Name မ်ား
@Name nvarchar(20),
@FName nvarchar(20),
@BDay nvarchar(15),
@Religion nvarchar(20),
@High nvarchar(15),
@BType nvarchar(5),
@Works nvarchar(50),
@Marks nvarchar(50), Table တည္ေဆာက္စဥ္က ေပးခဲ့တဲ့ Column Name
@Address nvarchar(100), မ်ား
@Pic varbinary(max)
AS
BEGIN
Insert Into Tbl_Main (No, ID, IssueDate, Name, FatherName, BirthDay, Religion, Hight, BloodType, Work, Mark,
Adress, Picture )
Values(@No, @ID, @IsDate, @Name, @FName, @BDay, @Religion, @High, @BType, @Works, @Marks,
@Address, @Pic)
END
။ ႕ ။ ႔ Tbl_Main Table
Column Field (14) ။ NoId Column Record
။ ႔ Identity ႔
။ ႔ Record / Auto
။ ႔ Column Field (13) ။
Command Line ။ ႔ Tbl_Main Table Insert ႕
Column Field(13) Variable(13) @ key Name(13)
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ Table Column Name ႔ ။
။ Data Type ႔ Amount
။
Insert Into Tbl_Main(Insert ႕ Column -Table Name )
Values(@ Insert Variable )
Fig.5
SQL Server frmMain Form Tbl_Main Table
၄ Table Record ႔ Insert_Main Stored
Procedure ႔ ။ ႔ Insert
frmMain Form ႕ UGI ။
Fig.6 ။ ႔ Project ႕ Insert
Picture Box ႔ ။ ႔
Picture Box ႔ ။
။ ။
Picture Box ႔
File Type UGI ႕ Picture Box ႔
။ Window Method ။
… ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Picture Box
Fig.6
1. Toolbox OpenFileDialog ႔ ႕ frmMain Form ႔ ။
႔ frmMain Form ႕ OpenFileDialog Box
႔ ။၄ Box ႕ Properties ။
2. ႔ ။
Control Name FileName
OpenFileDialog1 PicOpenFileDialog PicOFD
။ ႔ Picture Box ႔ ႔
Coding ႔ ။ ။
1. frmMain Form Picture Box D-Click Coding ႔ ။
႔ UGI picView ႔ Picture Box ႔ Coding
။
2. Coding Save and Run ။
private void picView_Click(object sender, EventArgs e)
{
if (PicOpenFileDialog.ShowDialog() == DialogResult.OK)
{
picView.ImageLocation = Path.GetFullPath(PicOpenFileDialog.FileName);
}
}
႔ PictureBox(picView) Click Open Dialog
PictureBox ႔ ။
။ Coding ႕ if( ) Statement ႔ ႔ ႕
OpenFileDialog Box Show ။ ၄ Box DialogResult User
OK(Open) if( ) {…} ႔
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ User Cancel if( ) Statement ။ Fig.7
။
Fig.7
User Open(OK) if( ) Statement ။ Coding
။ ႔ ႕ ImangeLocation ( ႔) File Path
OpenFileDialog1(PicOpenFileDialog) Box ႔
Picture Box(picView) ႔ ။ Fig.8
Result ။
Fig.8
Picture Box(picView) Click
။ Image File Type .jpeg, .png,
.ico, …., Image Type ။
႔ ႔ ။
… C# ႕ Library ႔ ။
picView.ImageLocation = Path.GetFullPath(PicOpenFileDialog.FileName);
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Command line Path.GetFullPath( ) Key C# ႕ Library Input/Output
Header File ။ Command Line ႔
႔ NameSpace(Header File) ။
using System.IO;
NameSpace Picture Box ႔ Image
Error Message ။ ။
။ ။ Image PictureBox
Button Coding ။
Sql Server Table Stored Procedure ႔၄ Sql Table
Stored Procedure C# ။
။ DataSet ၄ DataSet Table Adapter ႔
Table ။ OK, ႕ ႔။
Fig.9 Fig.10
1. Fig.9 ။ IDCheck_Tutorial(Project Name) DataSetFolder( ႔ Project ႕
DataSet Folder) R-Click Add New Item… Click
။ Fig.10 ႔ ။
2. ၄ Box DataSet Selected Name: Add
။ Tbl_Main ႕ DataSet ႔ DsMain.xsd ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.11
Fig.11 DataSet ႔ DataSetFolder
DsMain.xsd DataSet ႔ ။ OK.. DataSet
Tbl_Main Table ႔ ။ ႔ ။
Tbl_MainTableAdapter
႔ DsMain.xsd DataSet Tbl_Main
Table ။ ႔ ႔
။ ႔
။ ။
Fig.12 Fig.13
1. Fig.12 DsMain.xsd DataSet Page R-Click Add TableAdapter…
Click ။ Fig.13 ။
2. Which data connection should your application use to connect to the database ?
(၁) Database Connection (fig.12) ႔ Connection Name
Next (Window System ၄ Connection Name Auto
)။ Fig.14 ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.14 Fig.15
3. Use SQL statements Selected Next ။ Sql Command Line
Fig.15 ။
4. ၄ Select * From Tbl_Main ႔ command line Next ။
Tbl_Main Table Column Field ႔ ။
Fig.16 ။
Fig.16 Fig.17
5. Fig.16 Next Fig.17 Finish Fig.18 ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.18
Fig.18 Tbl_Main Table ႕ TableAdapter ။
႔ ႔ TableAdapter ႔ ႕ Insert_Main Stored
Procedure ။
Fig.19 Fig.20
1. Fig.19 Tbl_MainTableAdapter R-Click Add Query.. Click ။ Fig.20
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
2. ၄ Use existing stored procedure Selected Next ။ Stored
Procedure ႔ ႔ ႔ / Stored Procedure
႕ ႔ ။ Fig.21 ။
Fig.21 Fig.22
3. Fig.21 ႔ Stored Procedure Next ။
Table Tbl_Main Record Insert ႔ ႔
Insert_Main Stored Procedure ။
4. Fig.22 No value Selected Next ။
Fig.23 Fig.24
5. Fig.23 Next Fig.24 Finish ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.25
Fig.25 Tbl_MainTableAdapter Insert_Main Stored Procedure
႔ ။ ႔ ႔ ႕ C#
Coding Tbl_Main Table ( ႔) Record
႔ ။
C# Coding
။ ႔ Project Insert ႔ ႔ ။
႕ NameSpace ႔ ။
using System.Data.SqlClient;
SQL Coding Server C# Coding NameSpace
။ NameSpace
႕ Must Do ။
႔ DataSet TableAdapter coding
႔ variable ။
DataSetFolder.DsMainTableAdapters.Tbl_MainTableAdapter tblMain = new
DataSetFolder.DsMainTableAdapters.Tbl_MainTableAdapter();
႔ DataSetFolder Tbl_MainTableAdapter
tblMain Variable ။
႔ Coding Database
tblMain Variable ႔ Tbl_MainTableAdapter
C# Coding ။
SQL Server ႔ connection
။
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
command line ။ SQL Server ႔ conn
variable ။ Coding ႔
(၁) Fig.11,12,13 ။
။ C# Coding Sql Server ႔
Connection ။ ႔ ႔ Tbl_Main Table
( ႔) Record Coding ႕
။
႔ ။ ႔ Project
Record Image ႔ ။ Database ႕ Table Image Type
႔ ။
။ ႔
။ Image Type Byte Type Table
။ ႔ ။
႔ ႔ ႔ ။
႕ ။
႕ ။ ႔ ႔
။ ႕ ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ Command line ႔ Image File ႕
Fs Variable ။ line
႔ Image Binary ႔ BinaryReader Key
Br Variable ။ Line ႔
Binary No Result Database ႔ returnByte Variable
၄ returnByte Result ႔ Return ။
႔ PictureBox(picView) Image Byte Type Database
ConvertImageToByte( ) Function ႔ ။
… ႔ Database ႕ Tbl_Main Table ( ႔)
Record INSERT Button Coding ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
if( ) Statement ႔ Table ႕
Record (or) Column Filed(13) !=“” ( ႔) Record if
Statement ႕ {…} ႔ ။ ႔ !=“” ။
Record ႔ else {…} Statement
" Data ။" Message Box ။
Fig.26
Fig.26 ။ if( ) {…} else {…} Statement
႔ ။ Command line ႔။
If( ) Statemet !=“” if{…} ။
။ ႕ ႔ ။
}
tblMain.Insert_Main(txtNo.Text, txtID.Text, txtIssueDate.Text, txtFatherName.Text, txtName.Text, txtBirthDay.Text,
txtReligion.Text, txtHeight.Text, cbBloodType.Text.ToString(), txtWork.Text, txtMark.Text, txtAddress.Text,
ConvartImageToByte(picView.ImageLocation.ToString()));
MessageBox.Show(" ","Insert");
}
Tbl_MainTableAdapter ႔ Connection ႔ tblMain ႔ ႔
Variable ။ ၄ TableAdapter ႔ Tbl_MainTableAdapter
႔ Insert_Main Stored Procedure Insert_Main
Stored Procedure ။ ၄ ႔ Keyboard Record(13)
Insert_Main Stored Procedure ႕ @ ႔ Variable(13) ႔ Insert
။ ႔ frmMain.cs Form Data
SQL Server Tbl_Main Table ။
Command ႔ Image
ConvartImageToByte(picView.ImageLocation.ToString()) ႔
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
ConverImageToByte( ) Function Image Type Binary Type
။ Function ။
Screen Shoot ။
Fig.27
Fig.28(a)
Fig.28(b)
Fig.27 Record ႔ INSERT ။
Fig.28(a,b) ႔ SQL Server ႕ Tbl_Main Table ႔
Data ။ Table
႕ Picture Column Field ။ ႔ Image <Binary data>
႔ ။ ConvertImageToByte( )
Function Image Byte ႕ ႔ ။
႔ frmMain.cs ႕ Coding
။
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
using System.Data.SqlClient;
namespace IDCheck_Tutorial
{
public partial class frmMain : Form
{
DataSetFolder.DsMainTableAdapters.Tbl_MainTableAdapter tblMain = new
DataSetFolder.DsMainTableAdapters.Tbl_MainTableAdapter();
public frmMain()
{
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
InitializeComponent();
}
Setting ကိုႏွိပ္လိုက္တဲ့အခါ frmMain Form
private void linkSetting_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ ႀကီးေပ်ာက္သြားၿပီး frmSetting Form ေပၚလာ
this.Hide(); ေအာင္ ေရးထားတာပါ။
frmSetting showSetting = new frmSetting();
showSetting.ShowDialog();
}
Picture Box ကိုႏွိပ္ၿပီး မိမိစက္ထဲက Image
private void picView_Click(object sender, EventArgs e)
ေတြကို ေရြးယူႏိုင္ေအာင္ပါ။
{
if (PicOpenFileDialog.ShowDialog() == DialogResult.OK)
{
picView.ImageLocation = Path.GetFullPath(PicOpenFileDialog.FileName);
}
}
Image Type ကို Binary Type အျဖစ္ေျပာင္းၿပီး
byte[] ConvartImageToByte(string filesource)
{ သိမ္းႏိုင္ေအာင္ပါ။
FileInfo info = new FileInfo(filesource);
FileStream Fs = new FileStream(filesource, FileMode.Open, FileAccess.Read);
BinaryReader Br = new BinaryReader(Fs);
byte[] returnByte = Br.ReadBytes((int)Fs.Length);
return returnByte;
}
Tbl_Maing Table ကိုထဲကို Insert လုပ္ျခင္း အပို္င္းပါ။
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
if(txtNo.Text!="" & txtID.Text!="" & txtIssueDate.Text!="" & txtFatherName.Text!="" & txtName.Text!="" &
txtBirthDay.Text!="" & txtReligion.Text!="" & txtHeight.Text!="" & cbBloodType.Text!="" & txtWork.Text!="" &
txtMark.Text!="" & txtAddress.Text!="" & picView.ImageLocation!="")
{
tblMain.Insert_Main(txtNo.Text, txtID.Text, txtIssueDate.Text, txtFatherName.Text, txtName.Text,
txtBirthDay.Text, txtReligion.Text, txtHeight.Text, cbBloodType.Text.ToString(), txtWork.Text, txtMark.Text, txtAddress.Text,
ConvartImageToByte(picView.ImageLocation.ToString()));
MessageBox.Show(" ","Insert");
}
else
{
MessageBox.Show(" Data ။","Insert");
}
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Run ထားတဲ့ Program ႀကီးမွ အၿပီးတိုင္
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
ထြက္သြားႏိုင္ေအာင္ပါ။
{
Application.Exit();
}
}
}
Insert ။ ႔ Insert
Filter ။ ႔ Database Record
Program Error ။
႕ ။ ႔
႔ ။
။
႔ ႕
။ Insert Filter Tbl_Main Table
Data DataGridView Record Delete …
႔ ……
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
C# & Sql Server 2008 Tutorial (5)
။ ႔ ႕ C# & SQL
Database ။
Database ႔ ( ႔) Record
႔ ႔ (၅) ႔ ။
INSERT
႔ (၄)- ( ႔)
Record Tbl_Main Table ႔ ႕ ။
႔ INSERT ႔ ။
… Screen Shoot ။
Fig.1
Fig.2
Fig.(1,2) ႔ ။ ႔
Record Program Error
။ (၂)- Create User Account
။ ႔
။
INSERT Record Database
, ။
- ။ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ Column Field
( ႔ ႔
)။ ႔ ။ ႔
Record Database Insert ႔ ႔
။ ႔ Record ႕ ( ႔)
Database ။ Your Record is already exist. Message
Try Again. ။ ( ႔) Database
INSERT ။ OK… ႔
႕ ႔။
႔ Check ႔ SQL Command line
Query ။ ႔
။ ။
Fig.3 Fig.4
1. Fig.3 DsMain.xsd( ႕ Table ႕ Dataset) Tbl_MainTableAdapter R-
Click Add Query… ။ Fig.4 ။
2. Fig.4 Use SQL statement Selected Next ။ Fig.5
။
3. Fig.5 ႔ (No) Database /
(1) (0) Return
SELECT which returns a single value Selected Next ။ SQL Command line
Page ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.5 Fig.6
4. ၄ Page SQL Command line Next ။
Select Count(*) Form Tbl_Main
Where No=@No
႔ Keyboard (No) ႔
Database ႔
Count=1 Count=0 Query ။
။
Fig.7 Fig.8
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
5. Fig.7 Next ။ Database
(No) ႔ ChecktblMain_No
႔ ။
Fig.9
6. Fig.8 Finish ။ DsMain.xsd Dataset ႕
Tbl_MainTableAdapter ChecktblMain_No Sql Query
႔ ။
႔ Insert (No) ႔ Filter ။
၄ Query C# Coding ။
႔ ။ frmMain.cs Form INSERT Button D-Click
။ (၄) ႔ INSERT Coding
။
private void btnInsert_Click(object sender, EventArgs e)
{
try
{
if (txtNo.Text != "" & txtID.Text != "" & txtIssueDate.Text != "" & txtName.Text != "" & txtFatherName.Text != "" &
txtBirthDay.Text != "" & txtReligion.Text != "" & txtHeight.Text != "" & cbBloodType.Text != "" & txtWork.Text != "" &
txtMark.Text != "" & txtAddress.Text != "" & picView.ImageLocation != "")
{
int chkMain_No = int.Parse(tblMain.ChecktblMain_No(txtNo.Text).ToString());
if (chkMain_No == 0)
{
Check No အတြက္
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
else
{
MessageBox.Show(" Data ။","Insert");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Coding ႔ ….
int chkMain_No = int.Parse(tblMain.ChecktblMain_No(txtNo.Text).ToString());
if (chkMain_No == 0)
{
// If ( ) Statement ႕
}
else
{
// If ( ) Statement ႕
}
။ ။ ႔ Keyboard
(txtNo.Text) ChecktblMain_No Sql Query ႔ tblMain
Connection SQL Server (No) ႔
။ Record Database Count=1 ။ Count=0
Return ။ Result ႔ chkMain_No Variable
။ ႔ Result ။ Count=1( ႔)chkMain_No=1
႔ Database Record ။ ႔ Record
Your Record is already exist. Message Box ။ Count=0
( ႔) chkMain_No=0 ႔ (No) Database
။ Record ။ …
tblMain.Insert_Main(txtNo.Text, txtID.Text, txtIssueDate.Text, txtName.Text, txtFatherName.Text, txtBirthDay.Text,
txtReligion.Text, txtHeight.Text, cbBloodType.Text.ToString(), txtWork.Text, txtMark.Text, txtAddress.Text,
ConvartImageToByte(picView.ImageLocation.ToString()));
Command line Run ႔ Record Tbl_Main Table
။ Screen Shoot
။
1. Fig.10 ႔ Record Database ႔ Error
Message ။ ႔ SQL Query -
T111111 ။ T111111 ႔ Database ။
Else( ) Statement ႕ Message ။
2. Fig.11 ႔ Record ။
႔ (T222222) Database ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Insert_Main Stored Procedure Success Message
။
Fig.10
Fig.11
Fig.12
Fig.12 ႔ Record SQL Server Tbl_Main Table
။ ႔ ႔ ႕ Database Tbl_Main
Table ။ ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ Insert Record
Tbl_Main Table / SQL Server ။
႔ C# UGI DataGridView
။
Fig.13
1. Fig.13 ။ ႔ UGI DataGridView(DgvRecord) ႕
Click ။ ႔
DataGridView Tasks ။
2. Choose Data Source DataGridView(DgvRecord) Table
။ Other Data Sources Project Data Sources
DataSetFolder(DataSet Folder) DsMain( Table
DataSet) Tbl_Main( Table) ။
Fig.14
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
3. Fig.14 ။ DataGridView(DgvRecord) ႔
Tbl_Main Table ။
4. frmMain.cs Coding Private
Void { } Function ႔ ႔ tbl_MainTableAdapter Tbl_Main Table Data
Fill Coding ႔ ။
private void frmMain_Load(object sender, EventArgs e)
{
// TODO: This line of code loads data into the 'dsMain.Tbl_Main' table. You can move, or remove it, as needed.
this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main);
}
5. Run Fig.15 Result ။
Fig.15
Tbl_Main Table ႔ Insert Record ႔ ။ Fig.15
။ ႔ Table ႕ Column Title English No, ID, IssueDate,…
႔ SQL Server Table Name Column ႕
/ ႔ ။
႔ Column Title Column Width /
DataGridView ႕ Properties Change ။ ။
DataGridView(DgvRecord) ႕ Properties Change ….
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.16
( ႔)
Fig.17
1. Fig.16 DataGridView(DgvRecord) R-Click Edit Columns.. Click ။
( ႔)
Fig.17 DataGridView(DgvRecord) Selected ToolBox Columns
Collection Click ။ Fig.18 ။
Fig.18
2. ၄ Edit Columns Box Column ႕ Properties
။ Table ။ OK ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Selected Columns: Bound Column Properties
Control DataPropertyName HeaderText Width
NoId NoId 40
No No 70
ID ID 130
IssueDate IssueDate 80
Name Name 100
FatherName FatherName 100
BirthDay BirthDay 80
Religion Religion / 80
Hight Hight 80
BloodType BloodType 80
Work Work 150
Mark Mark 150
Adress Adress 200
Picture Picture 100
HeaderText
Width
Fig.19
Fig.20
Result ႔ ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ ။ Fig.19,20 ။
႔ DgvRecord (DataGridView) Column Field ႔
႔ ႔ ႔ ။ NoId( ) ႔ Identity Auto
Record ။ ႔ ႕
Record ႕ SQL Server ။
Auto Sorting No
(Fig.19 ႕ Column Title )။ Fig.20 ႕ Column ႔
Image ႔ ။ ။
႔ Column Field DataGridView(DgvRecord) ႕
။ ႔ ။
Fig.21
1. Fig.21 DataGridView(DgvRecord) R-Click Edit Columns… Click
။ Fig.22 ။
Fig.22 Fig.23
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
2. Fig.22 Column Field Selected Reomve Button Click
။ NoId( ) ႔ Picture( ) Column Field
Remove ။
3. Remove Fig.23 ။ OK
။
Fig.24
႔ Project Run Fig.24 DataGridView
(DgvRecord) Column Field ။
။ ။ ႔ Remove Column Field Add
Button Click ။ ႔ ႔ DataGridView
(DgvRecord) Column SQL Server Table
Column Field ။
႕ Column Selected Fig.23
Up and Down Button ႕ ႕ ။
႔ Table DataGridView ႔
၄ Table Column
Column Table Column
႔ ႔ ။ ႔
။ ႔ ႔ ႔ ။
႔ ႕ Database Table Record
DELETE Button Coding ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Tbl_Main Table Record Delete
SQL & C# ႔
။ Result
႔ ႔ ႔ ။ Table Record
Delete (၃)- User Account Delete
႔ ။ ႔ Stored procedure
SQL Qurey ။
႔ ။ SQL Query ။ …
႔ ။
Fig.25 Fig.26
1. SQL Query Fig.25 Tbl_MainTableAdapter R-
Click Add Query… Click ။
2. Fig.26 Use SQL statements Next ။
3. ႔ Record Delete Fig.27 DELETE Next
။ SQL Query Page ။
4. Fig.28 Command line Next ။
Delete From Tbl_Main
Where No = @No
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Where ႔ Database No ႔ ႔ Keyboard ႕ @No
။ Delete key ႔ Tbl_Main Table Record ႔
႔ ။ ႔ keyboard ႕ (No)
Database Delete ။ ။
Fig.27 Fig.28
5. Fig.29 SQL Query Name Next ။
Tbl_Main Table Record ႕ Query ႔
DelRecord_tblMain ႔ ။
Fig.29 Fig.30
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.31
6. Fig.30 ႔ Finish ။
7. ႔ ႕ Tbl_MainTableAdapter Fig.31
DelRecord_tblMain Query ။
႔ Tbl_Main Table Record Delete C# Coding ႔
။ ႔ DelRecord_tblMain Query C#
႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
}
}
}
else
{
MessageBox.Show(" ၏ ၄ Text Box ႔
။", "Delete");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Coding ။
။ Delete ။ …။
႔….
try
{
//Delete Coding
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
try{…}catch{..} Error ။ Coding
try{…} ။၄ try{…}
Error catch{…} Message Box ႔ ႔
။ Error Message ႔ ။ ႕
Error ႔ ။ ႔ ။ ႔ ႔
။
txtNo Text Box (txtNo.Text)
/ if statement ။ ၄ ….
if (txtNo.Text != "")
{
// (txtNo) Coding
}
else
{
MessageBox.Show(" ၏ ၄ Text Box ႔ ။",
"Delete");
}
Command line if(txtNo.Text != "") Statement ႔ ႔ ႕
(txtNo) Text Box / ။
( ႔) statement if{…} if Statement
else{…} ၏
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
၄ Text Box ႔ ။ Message ႔ TextBox
႔ (txtNo) ။
Fig.32
Fig.32 ႔ command line ႕ ႔
။ ႔ txtNo TextBox ႔
(No) / User
Command line ။
DialogResult Result = MessageBox.Show("ဤ Record ။", "Delete",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (Result == DialogResult.Yes)
{
//User (No) ( ႔)Yes Coding
}
။ ႔ Message Box ႔ Information Icon ႔ Yes
& No Button User ဤ Record ။ Messge ႔
။ User ႔ Result Variable
။ Statement User (Result)
DialogResult.Yes ႔ if{…} ။ User Yes
(No) ႔ Record
User No DELETE Delete Dialog
Box Exit ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.33
Fig.33 ႔ Coding ။ ….
int chkMain_No = int.Parse(tblMain.ChecktblMain_No(txtNo.Text).ToString());
if (chkMain_No == 1)
{
//Record Delete Coding
}
else
{
MessageBox.Show(" Delete ၏ Database ။ ","Delete");
}
Coding ChecktblMain_No ႔ INSERT
(No) ႔ ႔ Stored Procedure ႔ ။၄
Stored Procedure ႔ Delete Record Database(Tbl_Main
Table) / ။ Stored Procedure
… ႔ Keyboard (No) ႔ Database
႔ Count=1
Count=0 ။ Delete Record
Database ( ႔) Count==1 ၄ Record ႔ if{…}
Database ( ႔) Count==0 else{…}
Delete ၏ Database ။ Message ႔
။ ChecktblMain_No Stored Procedure
INSERT
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။
Fig.34
Fig.34 ႕ DataGridView(DgvRecord) Table Column Field ။ ႔
T555555 ။ Database ။
Delete ၏ Database ။ Message Box ။
။
႔ Coding …
tblMain.DelRecord_tblMain(txtNo.Text);
this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main);
MessageBox.Show(" ။", "Delete");
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
။ ႔ ႕ SQL Server ႕Tbl_Main Table
Record C# ႕ Tbl_MainTableAdapter Fill ။
Cmd ။
Cmd SQL Server ႕ Tbl_Main Table Record C# ႕
Tbl_MainTableAdapter Fill ႔ ။ ႔
DataGridView(DgvRecord) ႔ Data Tbl_MainTableAdapter
Record ။ Database INSERT Result
DataGridView(DgvRecord) DELETE Delete
Record Database DataGridView(DgvRecord)
။ ။
Fig.34
Fig.34 ။ ။ Message ႔ ႔
DataGridView(DgvRecord) ႕ Record T222222 Data
႔ ။ ႔ ။
။ ။ this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main); ။
႔ INSERT DELETE
Result DataGridView(DgvRecord) ။
႔ INSERT Tbl_Main Table / DELETE
Tbl_Main Table / SQL Server Tbl_Main
Table ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႔ ႔ Coding frmMain.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.IO;
using System.Data.SqlClient;
namespace IDCheck_Tutorial
{
public partial class frmMain : Form
{
DataSetFolder.DsMainTableAdapters.Tbl_MainTableAdapter tblMain = new
DataSetFolder.DsMainTableAdapters.Tbl_MainTableAdapter();
public frmMain()
{
SqlConnection conn = new SqlConnection(Properties.Settings.Default.IDCheckConString);
conn.Open();
InitializeComponent();
}
Setting ကိုႏွိပ္လိုက္တ့ဲအခါ frmMain Form
private void linkSetting_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e)
{ ႀကီးေပ်ာက္သြားၿပီး frmSetting Form
this.Hide(); ေပၚလာေအာင္ေရးထားတာပါ။
frmSetting showSetting = new frmSetting();
showSetting.ShowDialog();
}
Picture Box ကိုႏွိပ္ၿပီး မိမိစက္ထဲက Image
private void picView_Click(object sender, EventArgs e)
{ ေတြကို ေရြးယူႏိုင္ေအာင္ပါ
if (PicOpenFileDialog.ShowDialog() == DialogResult.OK)
{
picView.ImageLocation = Path.GetFullPath(PicOpenFileDialog.FileName);
}
}
Image Type Binary Type အျဖစ္ေျပာင္းၿပီး
byte[] ConvartImageToByte(string filesource)
{ သိမ္းႏိုင္ေအာင္ ။
FileInfo info = new FileInfo(filesource);
FileStream Fs = new FileStream(filesource, FileMode.Open, FileAccess.Read);
BinaryReader Br = new BinaryReader(Fs);
byte[] returnByte = Br.ReadBytes((int)Fs.Length);
return returnByte;
}
private void btnInsert_Click(object sender, EventArgs e) Tbl_Maing Table ထဲကို Insert လုပ္ျခင္း အပိုင္း ။
{
try
{
if (txtNo.Text != "" & txtID.Text != "" & txtIssueDate.Text != "" & txtName.Text != "" & txtFatherName.Text != "" &
txtBirthDay.Text != "" & txtReligion.Text != "" & txtHeight.Text != "" & cbBloodType.Text != "" & txtWork.Text != "" &
txtMark.Text != "" & txtAddress.Text != "" & picView.ImageLocation != "")
{
int chkMain_No = int.Parse(tblMain.ChecktblMain_No(txtNo.Text).ToString());
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
if (chkMain_No == 0)
{
tblMain.Insert_Main(txtNo.Text, txtID.Text, txtIssueDate.Text, txtName.Text, txtFatherName.Text,
txtBirthDay.Text, txtReligion.Text, txtHeight.Text, cbBloodType.Text.ToString(), txtWork.Text, txtMark.Text, txtAddress.Text,
ConvartImageToByte(picView.ImageLocation.ToString()));
this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main);
MessageBox.Show(" ", "Insert");
}
else
{
MessageBox.Show("Your Record is already exist in Database.","Insert");
}
}
else
{
MessageBox.Show(" Data ။","Insert");
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
Run ထားတဲ့ Program ႀကီးမွ အၿပီးတိုင္
private void frmMain_FormClosing(object sender, FormClosingEventArgs e)
ထြက္သြားႏိုင္ေအာင္ပါ။
{
Application.Exit();
}
Tbl_Main Tabl ကို DataGridView ေပၚသို႔ ဆြဲတင္တ့အ ဲ ခါ
private void frmMain_Load(object sender, EventArgs e)
ေပၚလာတာပါ။
{
// TODO: This line of code loads data into the 'dsMain.Tbl_Main' table. You can move, or remove it, as needed.
this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main);
}
Tbl_Main Tabl ထဲမွ Record ေတြကို
private void btnDelete_Click(object sender, EventArgs e)
{ Delete လုပ္ပစ္ျခင္း
try
{
if (txtNo.Text != "")
{
DialogResult Result = MessageBox.Show("ဤ Record ။", "Delete",
MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (Result == DialogResult.Yes)
{
int chkMain_No = int.Parse(tblMain.ChecktblMain_No(txtNo.Text).ToString());
if (chkMain_No == 1)
{
tblMain.DelRecord_tblMain(txtNo.Text);
this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main);
MessageBox.Show(" ။", "Delete");
}
else
{
MessageBox.Show(" Delete ၏ Database ။ ","Delete");
}
}
}
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
else
{
MessageBox.Show(" ၏ ၄ Text Box
႔ ။", "Delete");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
}
}
}
႔ ႕
။ UPDATE ႔
႔ ႔ ….
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Database Backup & Restore in SQL Server 2008
Fig.1
2. Fig.1 ႔ Database SQL Server Databases HR_DSA R-
Click Tasks Back Up… Click ။ Back Up Database Box
႔ ။
3. Back Up Database Box ။ Default
။ Fig.2 Setting ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.2
4. OK ။ Database Back Up
Fig.2 ႕ ။
Fig.3
5. Fig.3 HR_DSA Database ႔ Backup
Message Box ။
Fig.4
႔ Fig.2 ။ Fig.4
HR_DSA.bak Database Backup File ႔ ။ BackUp File
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
႕ SQL Server Import
။ ႔ Project Database File Delete ႔
Restore ။
Fig.5
1. Fig.5 ။ Database R-Click Delete
။
2. Delete Object Box ႔ Database
။ Fig.6 ။ OK ႔ Project ႕
Databases HR_DSA Database
႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.6
SQL Server ႔ Project
Database DELETE ႔ ။ ႔
႔ BackUp Database ႔ Restore
႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.7
2. Fig.8 Restore Database Box ႕ To database: Restore
BackUp Database Name ။ ။ ။
BackUp File Name ႔ ႔ Name ၀ ။ ႔ ။
Fig.8
3. Form Device: Selected Click ။ Specify Backup
Box ။
4. Fig.9 Box Add Button Click BackUp File
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.9
5. Fig.10 ႔ Restore Database BackUp File ႔
Selected OK ။
Fig.10
6. Fig.11 Specify Backup Box ။
။ OK ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.11
7. ႔ Fig.12 ႔ Database BackUp File
Selected OK ။
Fig.12
8. Fig.13 ႔ HR_DSA Database File
Restore Message Box ႔ ။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
Programmingknowledge.blogspot.com C# & Sql Server2008
---------------------------------------------------------------------------------------------------------------------
Fig.13
Fig.14
႔ Project ႕ Databases Folder ။ Fig.14
HR_DSA Database ႔ ။ ။
႔ Database Server Database File
BackUp Restore ႔ ။
႔ ႕
။
။
-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။