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.Threading.Tasks;
009.
using
System.Windows.Forms;
010.
using
System.Data.OleDb;
011.
012.
namespace
ProJSale
013.
{
014.
public
partial
class
Category : Form
015.
{
016.
private
OleDbConnection connection =
new
OleDbConnection();
017.
018.
public
Category()
019.
{
020.
InitializeComponent();
021.
connection.ConnectionString = @
"Provider=Microsoft.ACE.OLEDB.12.0;Data Source=D:\ProJSale\ProJSale\ProJSale.accdb;"
;
022.
}
023.
024.
private
void
Customer_Load(
object
sender, EventArgs e)
025.
{
026.
027.
this
.categoryTableAdapter.Fill(
this
.proJSaleDataSet.Category);
028.
this
.WindowState = FormWindowState.Maximized;
029.
}
030.
031.
private
void
btInsert_Click(
object
sender, EventArgs e)
032.
{
033.
try
034.
{
035.
connection.Open();
036.
OleDbCommand command =
new
OleDbCommand();
037.
command.Connection = connection;
038.
command.CommandText =
"insert into Category (ID_Category,NamethaiCategory,NameEngCategory) values('"
+ txtID_Category.Text +
"','"
+ txtNameThaiCategory.Text +
"','"
+ txtNameEngCategory.Text +
"')"
;
039.
040.
command.ExecuteNonQuery();
041.
MessageBox.Show(
"Data Saved"
);
042.
connection.Close();
043.
}
044.
catch
(Exception ex)
045.
{
046.
MessageBox.Show(
"Error"
+ ex);
047.
}
048.
}
049.
050.
private
void
btDelete_Click(
object
sender, EventArgs e)
051.
{
052.
try
053.
{
054.
connection.Open();
055.
OleDbCommand command =
new
OleDbCommand();
056.
command.Connection = connection;
057.
string
query =
"delete from Category where ID_Category = "
+ txtID_Category.Text +
" "
;
058.
command.CommandText = query;
059.
060.
command.ExecuteNonQuery();
061.
MessageBox.Show(
"Data Deleted"
);
062.
connection.Close();
063.
}
064.
catch
(Exception ex)
065.
{
066.
MessageBox.Show(
"Error"
+ ex);
067.
}
068.
}
069.
070.
private
void
btEdit_Click(
object
sender, EventArgs e)
071.
{
072.
try
073.
{
074.
connection.Open();
075.
OleDbCommand command =
new
OleDbCommand();
076.
command.Connection = connection;
077.
string
query =
"Update Category set ID_Category = '"
+ txtID_Category.Text +
"' ,NamethaiCategory = '"
+ txtNameThaiCategory.Text +
"' , where NameEngCategory = '"
+ txtNameEngCategory.Text +
"'"
;
078.
MessageBox.Show(query);
079.
command.CommandText = query;
080.
081.
command.ExecuteNonQuery();
082.
MessageBox.Show(
"Data Edit Successful"
);
083.
connection.Close();
084.
}
085.
catch
(Exception ex)
086.
{
087.
MessageBox.Show(
"Error"
+ ex);
088.
}
089.
}
090.
091.
private
void
btLoad_Click_1(
object
sender, EventArgs e)
092.
{
093.
try
094.
{
095.
connection.Open();
096.
OleDbCommand command =
new
OleDbCommand();
097.
command.Connection = connection;
098.
string
query =
"select * from Category "
;
099.
command.CommandText = query;
100.
101.
OleDbDataAdapter da =
new
OleDbDataAdapter(command);
102.
DataTable dt =
new
DataTable();
103.
da.Fill(dt);
104.
dataGridView1.DataSource = dt;
105.
106.
connection.Close();
107.
}
108.
catch
(Exception ex)
109.
{
110.
MessageBox.Show(
"Error"
+ ex);
111.
}
112.
}
113.
}
114.
}