01.
using
System;
02.
using
System.Collections.Generic;
03.
using
System.ComponentModel;
04.
using
System.Data;
05.
using
System.Data.OleDb;
06.
using
System.Drawing;
07.
using
System.Linq;
08.
using
System.Text;
09.
using
System.Windows.Forms;
10.
11.
namespace
Search_Form
12.
{
13.
public
partial
class
Search_Form : Form
14.
{
15.
public
Search_Form()
16.
{
17.
InitializeComponent();
18.
}
19.
20.
private
DataSet dsDataSet;
21.
22.
private
void
Search_Form_Load(
object
sender, EventArgs e)
23.
{
24.
25.
}
26.
27.
private
void
btnSearch_Click(
object
sender, EventArgs e)
28.
{
29.
30.
string
conStr =
"Provider=Microsoft.Ace.OleDb.12.0;"
+
31.
@
"Data Source=C:\Users\Plugfai\Documents\Visual Studio 2008\Projects\Bus_Aplication\Data\Bus Transport of Bangkok.accdb"
;
32.
OleDbConnection conn =
new
OleDbConnection(conStr);
33.
conn.Open();
34.
35.
36.
dsDataSet =
new
DataSet();
37.
OleDbCommand cmd;
38.
OleDbDataAdapter adapter;
39.
string
sql;
40.
string
BN = txtNum.Text;
41.
42.
if
(BN ==
""
)
43.
{
44.
MessageBox.Show(
"กรุณากรอกเลขสายค่ะ"
,
"error"
);
45.
}
46.
else
47.
{
48.
49.
sql =
"SELECT * FROM Bus_Lines WHERE Bus_Number="
+
"'"
+ BN +
"'"
;
50.
cmd =
new
OleDbCommand(sql, conn);
51.
adapter =
new
OleDbDataAdapter(cmd);
52.
adapter.Fill(dsDataSet,
"Bus"
);
53.
54.
try
55.
{
56.
If dsDataSet.Tables[
"Bus"
].Rows.Count=0 Then
throw
new
Exception(
"ไม่พบข้อมูล"
);
57.
txtShow.Text = dsDataSet.Tables[
"Bus"
].Rows[0][
"Ramble"
].ToString();
58.
59.
}
60.
catch
ex As Exception
61.
{
62.
Messagebox.Show(ex.Message);
63.
}
64.
}
65.
66.
67.
68.
69.
conn.Close();
70.
}
71.
}
72.
}