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

王朝oracle·作者佚名  2006-01-08
窄屏简体版  字體: |||超大  

所用的工具:vs.net beta2 ,orcale8

步骤:

1 在数据库中建一个Emp表,然后在其中加入EmpNo, EName, Sal, DeptNo四个字段。

2 打开vs.net beta2 创建一个c#工程-àwindows应用程序。对照以下代码:

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 )

{

if (components != null)

{

components.Dispose();

}

}

base.Dispose( disposing );

}

#region Windows Form Designer generated code

/// <summary>

/// Required method for Designer support - do not modify

/// the contents of this method with the code editor.

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航