001.
using
System;
002.
using
System.Collections.Generic;
003.
using
System.ComponentModel;
004.
using
System.Data;
005.
using
System.Drawing;
006.
using
System.Linq;
007.
using
System.Text;
008.
using
System.Windows.Forms;
009.
using
MySql.Data.MySqlClient;
010.
011.
namespace
YPApplication
012.
{
013.
public
partial
class
frmCustomer : Form
014.
{
015.
DataSet dataset =
new
DataSet();
016.
public
frmCustomer()
017.
{
018.
InitializeComponent();
019.
fillcboProvince();
020.
fillcboAmphur();
021.
fillcboDistrict();
022.
}
023.
024.
private
void
fillcboProvince()
025.
{
026.
try
027.
{
028.
DBConnect db =
new
DBConnect();
029.
030.
string
sql =
" select * from province "
;
031.
MySqlCommand SelectCommand =
new
MySqlCommand(sql, db.connection);
032.
db.OpenConnection();
033.
034.
MySqlDataAdapter dataadapter =
new
MySqlDataAdapter(SelectCommand);
035.
036.
dataadapter.Fill(dataset,
"province"
);
037.
038.
if
(dataset.Tables[
"province"
].Rows.Count > 0)
039.
{
040.
cboCusprovince.DisplayMember =
"PROVINCE_NAME"
;
041.
cboCusprovince.ValueMember =
"PROVINCE_ID"
;
042.
043.
cboCusprovince.DataSource = dataset.Tables[
"province"
];
044.
045.
}
046.
047.
048.
db.CloseConnection();
049.
050.
}
051.
catch
(Exception ex)
052.
{
053.
054.
MessageBox.Show(ex.Message);
055.
}
056.
}
057.
private
void
fillcboAmphur()
058.
{
059.
try
060.
{
061.
DBConnect db =
new
DBConnect();
062.
063.
string
sql =
" select * from amphur "
;
064.
MySqlCommand SelectCommand =
new
MySqlCommand(sql, db.connection);
065.
db.OpenConnection();
066.
067.
MySqlDataAdapter dataadapter =
new
MySqlDataAdapter(SelectCommand);
068.
069.
dataadapter.Fill(dataset,
"amphur"
);
070.
071.
if
(dataset.Tables[
"amphur"
].Rows.Count > 0)
072.
{
073.
cboCusamphur.DisplayMember =
"AMPHUR_NAME"
;
074.
cboCusamphur.ValueMember =
"AMPHUR_ID"
;
075.
076.
cboCusprovince.DataSource = dataset.Tables[
"amphur"
];
077.
}
078.
079.
080.
081.
db.CloseConnection();
082.
083.
}
084.
catch
(Exception ex)
085.
{
086.
087.
MessageBox.Show(ex.Message);
088.
}
089.
090.
091.
092.
093.
094.
}
095.
096.
private
void
fillcboDistrict()
097.
{
098.
try
099.
{
100.
DBConnect db =
new
DBConnect();
101.
102.
string
sql =
" select * from district "
;
103.
MySqlCommand SelectCommand =
new
MySqlCommand(sql, db.connection);
104.
db.OpenConnection();
105.
106.
MySqlDataAdapter dataadapter =
new
MySqlDataAdapter(SelectCommand);
107.
108.
dataadapter.Fill(dataset,
"district"
);
109.
110.
if
(dataset.Tables[
"district"
].Rows.Count > 0)
111.
{
112.
cboCusdistrict.DisplayMember =
"DISTRICT_NAME"
;
113.
cboCusdistrict.ValueMember =
"DISTRICT_ID"
;
114.
115.
cboCusprovince.DataSource = dataset.Tables[
"district"
];
116.
}
117.
118.
119.
120.
db.CloseConnection();
121.
122.
}
123.
catch
(Exception ex)
124.
{
125.
126.
MessageBox.Show(ex.Message);
127.
}
128.
129.
130.
131.
132.
133.
}
134.
135.
136.
}
137.
}