Connect Oracle Database by C # (5)

zhaozj2021-02-17  77

Application.run (new frmemp ());

}

Private void frMemp_load (Object Sender, System.EventArgs E)

{

}

Private void btnexit_click (Object Sender, System.Eventargs E)

{

CONN.CLOSE ();

THIS.CLOSE ();

}

Private void btnaddnew_click (Object Sender, System.Eventargs E)

{

TXTEMPNO.TEXT = ""

TXtename.text = ""

TXTESAL.TEXT = ""

TXTDEPTNO.TEXT = ""

TXTemPnO.focus ();

}

Private void btnsave_click (Object Sender, System.Eventargs E)

{

Try

{

IF (BlNEDIT == false)

{

DataRow1 = DataSet1.tables ["EMP"]. Newrow ();

DataRow1 ["Empno"] = INT16.PARSE (TXTemPno.Text);

DataRow1 ["ename"] = txtename.text;

DataRow1 ["sal"] = double.parse (txtesal.text);

Datarow1 ["deptno"] = int32.parse (txtDeptno.text);

DataSet1.Tables ["EMP"]. Rows.Add (DataRow1);

DataAdpt.Update (DataSet1, "EMP");

MessageBox.show ("Record Saved!");

}

Else

{

String str1;

Str1 = "Update EMP SET ENAME = '" TXtename.Text "", SAL = " Double.Parse (TXTESAL.TEXT) ", "

Str1 = str1 "deptno =" int16.Parse (txtDeptno.text) "where Empno =" INT16.PARSE (TXTemPno.Text);

Comm = New OLEDBCOMMAND (STR1,

Conn

);

Comm.executenonQuery ();

/*dredit.beginedit ();

Dredit ["ename"] = txtename.text;

Dredit ["sal"] = double.PARSE (TXTESAL.TEXT);

Dredit ["deptno"] = int16.parse (txtDeptno.text);

Dredit.endedit ();

DataAdpt.Update (DataSet1, "EMP"); * /

MessageBox.show ("Record Modified!");

}

}

Catch (Exception E1)

{

Messagebox.show (E1.toString ());

}

}

Private void btnedit_click (Object sender, system.eventargs e) {

String str1;

Try

{

Str1 = "SELECT * from EMP where Empno =" INT16.PARSE (TXTemPno.Text);

Comm = New OLEDBCOMMAND (STR1,

Conn

);

DTREAD = Comm.executeReader ();

IF (DTRead.Read ())

{

BLNEDIT = TRUE;

// Dredit = dataset1.tables ["EMP"]. Rows.Find (INT16.PARSE (TXTEMPNO.TEXT));

TXtename.text = DTREAD ["ename"]. TOSTRING ();

TXTESAL.TEXT = DTREAD ["sal"]. TOSTRING ();

TXTDEPTNO.TEXT = DTREAD ["deptno"]. TOSTRING ();

TXtename.focus ();

}

Else

{

TXtename.text = ""

TXTESAL.TEXT = ""

TXTDEPTNO.TEXT = ""

MessageBox.show ("Record Not Found!");

TXTemPnO.focus ();

}

DTREAD.CLOSE ();

}

Catch (Exception E1)

{

Messagebox.show (E1.toString ());

}

}

Private void btndelete_click (Object Sender, System.Eventargs E)

{

Try

{

Object str1;

String str2;

Str1 = MessageBox.Show ( "Do you want to delete the record", "Delete Box", System.Windows.Forms.MessageBoxButtons.YesNo, System.Windows.Forms.MessageBoxIcon.Warning); // == DialogResult.Yes)

IF (str1.toString () == "yes")

{

Str2 = "delete from Emp where Empno =" INT16.PARSE (TXTemPno.Text);

Comm = New OLEDBCOMMAND (STR2,

Conn

);

Comm.executenonQuery ();

MessageBox.show ("Record Has Been Deleded!");

TXTEMPNO.TEXT = ""

TXtename.text = ""

TXTESAL.TEXT = ""

TXTDEPTNO.TEXT = ""

TXTemPnO.focus ();

}

}

Catch (Exception EX)

{

Messagebox.show (ex.Message);

}

}

}

}

转载请注明原文地址:https://www.9cbs.com/read-31237.html

New Post(0)