using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb; // 엑세스 연동을 위한 네임스페이스
namespace findZipCode
{
public partial class FrmZipcode : Form
{
public FrmZipcode()
{
InitializeComponent();
}
public string GetConnString()
{
string databasePath = Application.StartupPath+"\\zip_db.mdb";
return @"provider=microsoft.JET.OLEDB.4.0;data source="+databasePath+"";
}
private void btn_Serach_Click(object sender, EventArgs e)
{
findprocess();
}
private void findprocess()
{
string strFindQry ="";
string strFindText = "";
lb_Zipcode.Items.Clear(); // 전체 리스트 박스 데이터 제거(초기화)
strFindText = textBox1.Text.Trim();
if (strFindText.Length == 0)
MessageBox.Show("검색할 주소의 동을 입력하세요 ", "경고");
else
{
strFindQry = "SELECT * FROM zipcode WHERE Dong LIKE '%"+strFindText+"%'";
fillListBox(strFindQry); //리스트박스 채우는 DB처리 메서트 실행
}
}
private void fillListBox(string strFindQry)
{
OleDbConnection conn = new OleDbConnection(GetConnString());
OleDbCommand cmd = new OleDbCommand(strFindQry,conn);
conn.Open();
OleDbDataReader reader= cmd.ExecuteReader();
while (reader.Read())
{
lb_Zipcode.Items.Add(reader["zipcode"]+","+reader["sido"]+","+reader["gugun"]+ ","+ reader["dong"] + ","+reader["bunji"]);
}
reader.Close();
conn.Close();
conn.Dispose();
}
private void textBox1_KeyPress(object sender, KeyPressEventArgs e)
{
if(Convert.ToInt32(e.KeyChar) == 13)
findprocess();
}
}
}