using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OracleClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Common; using Oracle.DataAccess;
globals.connectionString = "Data Source="+this.databaseName.Text.Trim()+";uid="+this.username.Text.Trim()+";pwd="+this.password.Text.Trim()+";"; globals.username = this.username.Text.Trim(); globals.databaseName = this.databaseName.Text.Trim();
using System; using System.Collections.Generic; using System.Linq; using System.Windows.Forms; namespace Net3._5_oracleTest { static class Program { /// <summary> /// 应用程序的主入口点。 /// </summary> [STAThread] static void Main() { Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Application.Run(new LoginForm()); } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OracleClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Net3._5_oracleTest { public partial class LoginForm : Form { public LoginForm() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { globals.connectionString = "Data Source="+this.databaseName.Text.Trim()+";uid="+this.username.Text.Trim()+";pwd="+this.password.Text.Trim()+";"; globals.username = this.username.Text.Trim(); globals.databaseName = this.databaseName.Text.Trim(); OracleConnection conn = new OracleConnection(globals.connectionString); try { conn.Open(); MessageBox.Show("已连接到Oracle数据库!"); MainForm mf = new MainForm(); this.Hide(); mf.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); }finally { conn.Close(); } } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OracleClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; namespace Net3._5_oracleTest { public partial class LoginForm : Form { public LoginForm() { InitializeComponent(); } private void textBox1_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { globals.connectionString = "Data Source="+this.databaseName.Text.Trim()+";uid="+this.username.Text.Trim()+";pwd="+this.password.Text.Trim()+";"; globals.username = this.username.Text.Trim(); globals.databaseName = this.databaseName.Text.Trim(); OracleConnection conn = new OracleConnection(globals.connectionString); try { conn.Open(); MessageBox.Show("已连接到Oracle数据库!"); MainForm mf = new MainForm(); this.Hide(); mf.Show(); } catch (Exception ex) { MessageBox.Show(ex.Message); }finally { conn.Close(); } } } }
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Data.OracleClient; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.Common; using Oracle.DataAccess; namespace Net3._5_oracleTest { public partial class GrideViews_UserInfo : Form { public GrideViews_UserInfo() { InitializeComponent(); } private void GrideViews_UserInfo_Load(object sender, EventArgs e) { string sql1 = "SELECT * FROM infoofuser"; OracleConnection myconn = new OracleConnection(globals.connectionString); OracleCommand mycmd = myconn.CreateCommand(); mycmd.CommandText = sql1; myconn.Open(); OracleDataAdapter oraDA = new OracleDataAdapter(mycmd); DataSet ds = new DataSet(); oraDA.Fill(ds); myconn.Close(); DataTable dtbl = ds.Tables[0]; this.dataGridView1.DataSource = dtbl; } } }
原文地址:http://blog.csdn.net/shinepan/article/details/46460083