24 - 윈폼 - ver4 - 소스 - 최종
24 - 윈폼 - ver4 - 소스 - 최종
MessageBox.Show(DE.Message);
//ver4 }
catch (Exception DE)
===== form1 ======== {
using System; MessageBox.Show(DE.Message);
using System.Collections.Generic; }
using System.ComponentModel; }
using System.Data;
using System.Drawing; private void AppendBtn_Click(object sender, EventArgs e)
using System.Linq; {
using System.Text; try
using System.Windows.Forms; {
using Oracle.DataAccess.Client; MessageBox.Show("텍스트 상자에 모든 데이터 입력
namespace ADOForm 하셨으면 추가합니다!");
{ // DS.Clear();//*
public partial class Form1 : Form
{ // DBAdapter.Fill(DS, "Phone");//*
new Form1 Parent; //*****
dbc.PhoneTable = dbc.DS.Tables["Phone"];//*
/* 중복 되는 부분 DataRow newRow = dbc.PhoneTable.NewRow();
newRow["id"] =Convert.ToInt32(txtid.Text);
//수정하거나 삭제하기 위해 선택된 행의 인덱스를 저장한다. newRow["PName"] = txtName.Text;
private int SelectedRowIndex; newRow["Phone"] = txtPhone.Text;
newRow["Email"] = txtMail.Text;
// Data Provider인 DBAdapter 입니다.
OracleDataAdapter DBAdapter; dbc.PhoneTable.Rows.Add(newRow);
dbc.DBAdapter.Update(dbc.DS, "Phone");
// DataSet 객체입니다. dbc.DS.AcceptChanges();//*
DataSet DS; ClearTextBoxes(); //*
DBGrid.DataSource =
// 추가, 수정, 삭제시에 필요한 명령문을 dbc.DS.Tables["Phone"].DefaultView;
// 자동으로 작성해주는 객체입니다. }
OracleCommandBuilder myCommandBuilder; catch (DataException DE)
{
// ataTable 객체입니다. MessageBox.Show(DE.Message);
DataTable phoneTable; }
catch (Exception DE)
// 수정, 삭제할 때 필요한 레코드의 키값을 보관할 필드 {
private int SelectedKeyValue; MessageBox.Show(DE.Message);
}
}
private void DB_Open()
{ private void dataGridView1_CellClick(object sender,
try DataGridViewCellEventArgs e)
{ {
string connectionString = "User Id=honga1; try
Password=1111; Data Source=(DESCRIPTION = (ADDRESS = {
(PROTOCOL = TCP)(HOST = localhost)(PORT = 1521)) // DataSet DS = new DataSet();//*
(CONNECT_DATA = (SERVER = DEDICATED) //DBAdapter.Fill(DS, "Phone");
(SERVICE_NAME = xe) ) );";
DataTable phoneTable = dbc.DS.Tables["Phone"];
string commandString = "select * from Phone";
if (e.RowIndex < 0)
DBAdapter = new {
OracleDataAdapter(commandString, connectionString); // DBGrid의 컬럼 헤더를 클릭하면 컬럼을 정렬하므
myCommandBuilder = new 로
OracleCommandBuilder(DBAdapter); // 아무 메시지도 띄우지 않습니다.
return;
DS = new DataSet(); }
} else if (e.RowIndex > phoneTable.Rows.Count - 1)
catch (DataException DE) {
{ MessageBox.Show("해당하는 데이터가 존재하지 않
MessageBox.Show(DE.Message); 습니다.");
} return;
} }
중복 끝 */
DataRow currRow = phoneTable.Rows[e.RowIndex];
DBClass dbc = new DBClass(); //*****DBClass 객체 생성 txtid.Text = currRow["id"].ToString();
private void ClearTextBoxes() txtName.Text = currRow["PName"].ToString();
{ txtPhone.Text = currRow["Phone"].ToString();
txtid.Clear(); txtMail.Text = currRow["EMail"].ToString();
txtName.Clear();
txtPhone.Clear(); dbc.SelectedRowIndex =
txtMail.Clear(); Convert.ToInt32(currRow["id"]);
} }
public Form1() catch (DataException DE)
{ {
InitializeComponent(); MessageBox.Show(DE.Message);
dbc.DB_ObjCreate(); //***** }
dbc.DB_Open();//***** catch (Exception DE)
} {
MessageBox.Show(DE.Message);
}
private void DAOpenBtn_Click(object sender, EventArgs e) }
{
try private void UpdateBtn_Click(object sender, EventArgs e)
{ {
dbc.DS.Clear(); try
dbc.DBAdapter.Fill(dbc.DS, "phone"); {
// phoneTable = DS.Tables["Phone"];//* //DS.Clear();
DBGrid.DataSource = //DBAdapter.Fill(DS, "Phone");
dbc.DS.Tables["phone"].DefaultView;
}
catch (DataException DE) dbc.PhoneTable = dbc.DS.Tables["Phone"];//*
DataColumn[] PrimaryKey = new DataColumn[1]; ====form2===================
PrimaryKey[0] = dbc.PhoneTable.Columns["id"]; using System;
dbc.PhoneTable.PrimaryKey = PrimaryKey; using System.Collections.Generic;
using System.ComponentModel;
DataRow currRow = using System.Data;
dbc.PhoneTable.Rows.Find(dbc.SelectedRowIndex); using System.Drawing;
using System.Linq;
currRow.BeginEdit(); using System.Text;
currRow["id"] = txtid.Text; using System.Windows.Forms;
currRow["PName"] = txtName.Text; using Oracle.DataAccess.Client;
currRow["Phone"] = txtPhone.Text; namespace ADOForm
currRow["EMail"] = txtMail.Text; {
currRow.EndEdit(); public partial class Form2 : Form
{
DataSet UpdatedSet = new Form1 Parent; //*****
dbc.DS.GetChanges(DataRowState.Modified);
if (UpdatedSet.HasErrors) /* 중복 되는 부분
{
MessageBox.Show("변경된 데이터에 문제가 있 //수정하거나 삭제하기 위해 선택된 행의 인덱스를 저장한다.
습니다."); private int SelectedRowIndex;
}
else // Data Provider인 DBAdapter 입니다.
{ OracleDataAdapter DBAdapter;
dbc.DBAdapter.Update(UpdatedSet, "Phone");
dbc.DS.AcceptChanges(); // DataSet 객체입니다.
} DataSet DS;
namespace ADOForm
{
public class DBClass //DBClass 정의 시작
{
private int selectedRowIndex;//수정하거나 삭제하기 위해 선택된 행
의 인덱스를 저장한다.
private int selectedKeyValue; // 수정, 삭제할 때 필요한 레코드의 키
값을 보관할 필드