通过c#连结oracle数据库(三)

原创 2001年10月15日 09:03:00

// <?xml:namespace prefix = o ns = "urn:schemas-microsoft-com:office:office" />

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 = "FrmEmp";

this.Text = "Employee Data Form";

this.Load += new System.EventHandler(this.FrmEmp_Load);

this.ResumeLayout(false);

}

#endregion

/// <summary>

/// The main entry point for the application.

/// </summary>

[STAThread]

static void <?xml:namespace prefix = st1 ns = "urn:schemas-microsoft-com:office:smarttags" />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 deleted!");

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 Employee

{

/// <summary>

/// Summary description for Form1.

/// </summary>

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;

/// <summary>

/// Required designer variable.

/// </summary>

private System.ComponentModel.Container components = null;

public FrmEmp()

{

//

// Required for Windows Form Designer support

//

InitializeComponent();

ConnStr = "Provider=MSDAORA;DSN=oracle;User ID=system;Password=manager";

Conn = new OleDbConnection(ConnStr);

Conn.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 constructor code after InitializeComponent call

//

}

/// <summary>

/// Clean up any resources being used.

/// </summary>

protected override void Dispose( bool disposing )

{

if( disposing )

通过c#连结oracle数据库(一)

所用的工具:vs.net beta2 ,orcale8 步骤:     1 在数据库中建一个Emp表,然后在其中加入EmpNo, EName, Sal, DeptNo四个字段。     2 打开vs....
  • willsound
  • willsound
  • 2001年10月15日 09:01
  • 592

通过c#连结oracle数据库(五)

Application.Run(new FrmEmp()); } private void FrmEmp_Load(object sender, System.EventArgs e) { } pri...
  • willsound
  • willsound
  • 2001年10月15日 09:04
  • 714

通过c#连结oracle数据库(二)

/// private void InitializeComponent() { this.label4 = new System.Windows.Forms.Label(); this.BtnEx...
  • willsound
  • willsound
  • 2001年10月15日 09:02
  • 577

通过c#连结oracle数据库(四)

{ if (components != null) { components.Dispose(); } } base.Dispose( disposing ); } #region Windows F...
  • willsound
  • willsound
  • 2001年10月15日 09:03
  • 585

用C#连结ORACLE数据库

 Standard   security:         "Provider=msdaora;Data   Source=MyOracleDB;User   Id=UserName;Password...
  • justin_hua
  • justin_hua
  • 2008年01月04日 16:05
  • 388

C# 连结access

using System;using System.Data;using System.Configuration;using System.Web;using System.Web.Security...
  • evan02
  • evan02
  • 2010年03月04日 15:38
  • 217

Excel导入Oracle数据库C#winform完整代码

将execl中的数据导入到数据库中 思路: 先将 execl中的数据 动态的添加到dataset 中 再用for将datarow的对象插入到数据库中! 当然为了 防止出错要用事务!   ...
  • qq_27317147
  • qq_27317147
  • 2016年07月21日 15:59
  • 1172

C#连接Oracle数据库的一种方法(详细过程)

1. 需要添加一个System.Data.OracleClient引用,这个文件一般在C:\Program Files (x86)\Reference Assemblies\Microsoft\Fra...
  • u013797023
  • u013797023
  • 2017年11月11日 20:28
  • 453

C#远程连接Oracle数据库(通过System.Data.OracleClient)

转自:https://my.oschina.net/Tsybius2014/blog/299125 在.NET中使用System.Data.OracleClient库连接Oracle数据库的步骤...
  • shellching
  • shellching
  • 2016年11月11日 14:28
  • 3282

C#面向对象三大特性

想要学好面向对象编程,除了掌握语法结构外最重要的就是熟悉面向对象三大特性,这三大特性不是相互独立的而是相互关联、你中有我我中有你的关系,想要真正了解三大特性必须把这三部分当做一个整体来考虑。...
  • xiaouncle
  • xiaouncle
  • 2016年11月23日 21:02
  • 2728
内容举报
返回顶部
收藏助手
不良信息举报
您举报文章:通过c#连结oracle数据库(三)
举报原因:
原因补充:

(最多只允许输入30个字)