Connect Oracle Database by C # (3)

zhaozj2021-02-17  81

//

THIS.AUTOSCALEBASESIZE = New System.drawing.size (6, 14);

This.ClientSize = new system.drawing.size (576, 317);

this.controls.addrange (new system.windows.forms.control] {

this.btnexit,

this.btndelete,

this.btnedit,

this.btnsave,

this.btnaddnew,

THIS.TXTDEPTNO,

THIS.TXTESAL,

this.txtename,

THIS.TXTEMPNO,

THIS.LABEL4,

THIS.Label3,

THIS.LABEL2,

THIS.LABEL1});

This.Font = New System.drawing.Font ("Microsoft Sans Serif", 9F, System.drawing.FontStyle.Bold, System.drawing.graphicsUnit.Point, ((System.byte) (0)));

THIS.NAME = "fmemp";

THIS.TEXT = "Employee Data Form";

THISLOAD = New System.EventHandler (this.frmemp_load);

This.ResumeLayout (false);

}

#ndregion

///

/// The main entry point for the application.

///

[Stathread]

Static void

Main

()

{

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);

}

}

}

}

Using system;

Using system.drawing;

Using system.collections;

Using system.componentmodel;

Using system.windows.forms;

Using system.data;

Using system.data.oledb;

Namespace EMPLOYEEEEEE

{

///

/// summary description for Form1.

///

Public class frMemp: system.windows.forms.form

{

Private system.windows.Forms.Label label1;

Private system.windows.Forms.Label label2;

Private system.windows.Forms.Label label3;

Private system.windows.Forms.Label label4;

Private system.windows.Forms.TextBox txtempno;

Private system.windows.Forms.TextBox TXtename;

Private system.windows.Forms.TextBox TXTESAL;

Private system.windows.Forms.TextBox txtDeptno;

Private system.windows.forms.button btnaddnew;

Private system.windows.Forms.Button Btnsave;

Private system.windows.Forms.Button Btndelete;

Private system.windows.Forms.Button Btnexit;

Private

System.Data.Oledb.oledbconnection

Conn

;

Private system.data.oledb.oledbcommand comm; private system.data.oledb.oledbdataadapter dataadpt;

Private system.data.oledb.oledbcommandbuilder cbuild;

Private system.data.oledb.oledbdatareader dtread;

Private system.data.dataset dataset1;

Private system.data.datarow datarow1;

Private system.data.DataTable DataTable1;

PRIVATE STRING CONNSTR;

Private bool blnedit;

Private system.windows.Forms.Button btnedit;

///

/// Required Designer Variable.

///

Private system.componentmodel.Container Components = NULL;

Public FRMEMP ()

{

//

// Required for Windows Form Designer Support

//

InitializationComponent ();

CONNSTR = "provider = msdara; dsn = oracle; user ID = system; password = manager";

Conn

= New OLEDBCONNECTION (Conntr);

Cn.open ();

DataAdpt = New OledbDataAdapter ("SELECT * FROM EMP",

Conn

);

CBUILD = New OLEDBCommandbuilder (DataAdpt);

DataSet1 = New DataSet ("EMP");

DataTable1 = New DataTable ("EMP");

DataAdpt.Fill (DataSet1, "EMP");

//

// Todo: Add Any Constructionor Code After InitializationComponent Call

//

}

///

/// Clean Up Any Resources Being Used.

///

Protected Override Void Dispose (Bool Disposing)

{

IF (Disposing)

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

New Post(0)