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

C & SQL Server 2008 Tutorial - 5

The document discusses C# and SQL Server 2008 tutorials for database operations. It covers inserting records into a database table using C# code. The tutorials include screenshots and explanations of creating a dataset and table adapter in Visual Studio, writing an INSERT query, and coding an INSERT button click event handler in C# to insert data into the database table. It also covers checking for duplicate records before insertion using a COUNT query.

Uploaded by

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

C & SQL Server 2008 Tutorial - 5

The document discusses C# and SQL Server 2008 tutorials for database operations. It covers inserting records into a database table using C# code. The tutorials include screenshots and explanations of creating a dataset and table adapter in Visual Studio, writing an INSERT query, and coding an INSERT button click event handler in C# to insert data into the database table. It also covers checking for duplicate records before insertion using a COUNT query.

Uploaded by

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

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 အတြက္

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()));
MessageBox.Show(" ", "Insert");
}
else
{
MessageBox.Show("Your Record is already exist in Database.","Insert");
}
}

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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

Tbl_Main Table Record DataGridView(DgvRecord) ႔



႔ Data
Resurt ။ ။

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

႔ frmMain.cs Form ႕ DataGridView(DgvRecord)


႔ ။

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) ႕
။ ႔ ။

DataGridView(DgvRecod) Column Field


DataGridView(DgvRecord) Column Field ႔
။ ။

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 ။ …
႔ ။

Delete Record SQL Query


႔ Tbl_Main Table Record
IDCheck_Tutorial  DataSetFolder  DsMain.xsd Dataset Page ႕

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#
႔ ။

Delete Tbl_Main’s Record C# Coding


႔ Tbl_Main Table Insert Record
Record Delete ။ Coding frmMain.cs
။ SQL Server ႔ Connection ႕ INSERT
႔ ။ ႔
။ …..
1. frmMain.cs Form ႕ DELEDE Button D-Click frmMain.cs ႕ Coding ။
2. ၄ DELETE Button Command Line Run ။
private void btnDelete_Click(object sender, EventArgs e)
{
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);
}
}
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");

႔ ႔ ။ Comand line Delete Record SQL


Query ႔ DelRecord_tblMain SQL Query
႔ Keyboard (txtNo) Database ႕
Tbl_Main Table (No) ႔ ။
Command line this.tbl_MainTableAdapter.Fill(this.dsMain.Tbl_Main);

႔ Tbl_Main Table DataGridView(DgvRecord) ႔ frmMain form load


Command line ။
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);
}

-----------------------------------------------------------------------------------------------------------
႔၏ ႔…။
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 ႔
႔ ႔ ….

C# and SQL Server 2008 (5 ။ ႔



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

Tay Zar Lin


[email protected]
Programmingknowledge.blogspot.com

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

You might also like