⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 frmysjy.cs

📁 可将ACCESS数据库导入到Oracle数据库
💻 CS
字号:
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using Microsoft.Win32;

namespace DataC
{
	/// <summary>
	/// Summary description for frmYSJY.
	/// </summary>
	public class frmYSJY : System.Windows.Forms.Form
	{
		public
			string strConn=null;
		private System.Windows.Forms.GroupBox groupBox1;
		private System.Windows.Forms.TextBox tbDBN;
		private System.Windows.Forms.TextBox tbPW;
		private System.Windows.Forms.TextBox tbUN;
		private System.Windows.Forms.Label label5;
		private System.Windows.Forms.ComboBox cbType;
		private System.Windows.Forms.Label label4;
		private System.Windows.Forms.Label label3;
		private System.Windows.Forms.Label label1;
		private System.Windows.Forms.Button button1;
		private System.Windows.Forms.Button btOK;
		private System.Windows.Forms.OpenFileDialog ofd;
		private System.Windows.Forms.Label lbODBC;
		private System.Windows.Forms.ComboBox cbODBC;
		private System.Windows.Forms.Label lbSql;
		private System.Windows.Forms.TextBox tbSql;

		
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public frmYSJY()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// 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.
		/// </summary>
		private void InitializeComponent()
		{
			this.groupBox1 = new System.Windows.Forms.GroupBox();
			this.tbSql = new System.Windows.Forms.TextBox();
			this.lbSql = new System.Windows.Forms.Label();
			this.btOK = new System.Windows.Forms.Button();
			this.button1 = new System.Windows.Forms.Button();
			this.tbDBN = new System.Windows.Forms.TextBox();
			this.tbPW = new System.Windows.Forms.TextBox();
			this.tbUN = new System.Windows.Forms.TextBox();
			this.label5 = new System.Windows.Forms.Label();
			this.cbODBC = new System.Windows.Forms.ComboBox();
			this.cbType = new System.Windows.Forms.ComboBox();
			this.label4 = new System.Windows.Forms.Label();
			this.label3 = new System.Windows.Forms.Label();
			this.lbODBC = new System.Windows.Forms.Label();
			this.label1 = new System.Windows.Forms.Label();
			this.ofd = new System.Windows.Forms.OpenFileDialog();
			this.groupBox1.SuspendLayout();
			this.SuspendLayout();
			// 
			// groupBox1
			// 
			this.groupBox1.Controls.Add(this.tbSql);
			this.groupBox1.Controls.Add(this.lbSql);
			this.groupBox1.Controls.Add(this.btOK);
			this.groupBox1.Controls.Add(this.button1);
			this.groupBox1.Controls.Add(this.tbDBN);
			this.groupBox1.Controls.Add(this.tbPW);
			this.groupBox1.Controls.Add(this.tbUN);
			this.groupBox1.Controls.Add(this.label5);
			this.groupBox1.Controls.Add(this.cbODBC);
			this.groupBox1.Controls.Add(this.cbType);
			this.groupBox1.Controls.Add(this.label4);
			this.groupBox1.Controls.Add(this.label3);
			this.groupBox1.Controls.Add(this.lbODBC);
			this.groupBox1.Controls.Add(this.label1);
			this.groupBox1.Location = new System.Drawing.Point(1, -5);
			this.groupBox1.Name = "groupBox1";
			this.groupBox1.Size = new System.Drawing.Size(263, 221);
			this.groupBox1.TabIndex = 14;
			this.groupBox1.TabStop = false;
			// 
			// tbSql
			// 
			this.tbSql.Location = new System.Drawing.Point(88, 56);
			this.tbSql.Name = "tbSql";
			this.tbSql.Size = new System.Drawing.Size(120, 21);
			this.tbSql.TabIndex = 1;
			this.tbSql.Text = "";
			// 
			// lbSql
			// 
			this.lbSql.AutoSize = true;
			this.lbSql.Location = new System.Drawing.Point(11, 56);
			this.lbSql.Name = "lbSql";
			this.lbSql.Size = new System.Drawing.Size(72, 17);
			this.lbSql.TabIndex = 25;
			this.lbSql.Text = "Sql服务器名";
			// 
			// btOK
			// 
			this.btOK.Location = new System.Drawing.Point(152, 184);
			this.btOK.Name = "btOK";
			this.btOK.TabIndex = 24;
			this.btOK.Text = "确定";
			this.btOK.Click += new System.EventHandler(this.btOK_Click);
			// 
			// button1
			// 
			this.button1.Location = new System.Drawing.Point(224, 88);
			this.button1.Name = "button1";
			this.button1.Size = new System.Drawing.Size(32, 23);
			this.button1.TabIndex = 23;
			this.button1.Text = "...";
			this.button1.Click += new System.EventHandler(this.button1_Click);
			// 
			// tbDBN
			// 
			this.tbDBN.Location = new System.Drawing.Point(88, 88);
			this.tbDBN.Name = "tbDBN";
			this.tbDBN.Size = new System.Drawing.Size(136, 21);
			this.tbDBN.TabIndex = 2;
			this.tbDBN.Text = "";
			// 
			// tbPW
			// 
			this.tbPW.Location = new System.Drawing.Point(88, 152);
			this.tbPW.Name = "tbPW";
			this.tbPW.PasswordChar = '#';
			this.tbPW.Size = new System.Drawing.Size(120, 21);
			this.tbPW.TabIndex = 4;
			this.tbPW.Text = "";
			// 
			// tbUN
			// 
			this.tbUN.Location = new System.Drawing.Point(88, 120);
			this.tbUN.Name = "tbUN";
			this.tbUN.Size = new System.Drawing.Size(120, 21);
			this.tbUN.TabIndex = 3;
			this.tbUN.Text = "";
			// 
			// label5
			// 
			this.label5.AutoSize = true;
			this.label5.Location = new System.Drawing.Point(29, 88);
			this.label5.Name = "label5";
			this.label5.Size = new System.Drawing.Size(54, 17);
			this.label5.TabIndex = 21;
			this.label5.Text = "数据库名";
			// 
			// cbODBC
			// 
			this.cbODBC.Location = new System.Drawing.Point(88, 56);
			this.cbODBC.Name = "cbODBC";
			this.cbODBC.Size = new System.Drawing.Size(121, 20);
			this.cbODBC.TabIndex = 20;
			// 
			// cbType
			// 
			this.cbType.Items.AddRange(new object[] {
														"Access数据库",
														"SQLserver数据库",
														"Oracle数据库"});
			this.cbType.Location = new System.Drawing.Point(88, 21);
			this.cbType.Name = "cbType";
			this.cbType.Size = new System.Drawing.Size(121, 20);
			this.cbType.TabIndex = 0;
			this.cbType.Text = "Access数据库";
			this.cbType.SelectedIndexChanged += new System.EventHandler(this.cbType_SelectedIndexChanged);
			// 
			// label4
			// 
			this.label4.AutoSize = true;
			this.label4.Location = new System.Drawing.Point(51, 153);
			this.label4.Name = "label4";
			this.label4.Size = new System.Drawing.Size(29, 17);
			this.label4.TabIndex = 16;
			this.label4.Text = "密码";
			// 
			// label3
			// 
			this.label3.AutoSize = true;
			this.label3.Location = new System.Drawing.Point(40, 123);
			this.label3.Name = "label3";
			this.label3.Size = new System.Drawing.Size(42, 17);
			this.label3.TabIndex = 15;
			this.label3.Text = "用户名";
			// 
			// lbODBC
			// 
			this.lbODBC.AutoSize = true;
			this.lbODBC.Location = new System.Drawing.Point(8, 56);
			this.lbODBC.Name = "lbODBC";
			this.lbODBC.Size = new System.Drawing.Size(79, 17);
			this.lbODBC.TabIndex = 14;
			this.lbODBC.Text = "ODBC数据源名";
			this.lbODBC.Visible = false;
			// 
			// label1
			// 
			this.label1.AutoSize = true;
			this.label1.Location = new System.Drawing.Point(18, 24);
			this.label1.Name = "label1";
			this.label1.Size = new System.Drawing.Size(66, 17);
			this.label1.TabIndex = 13;
			this.label1.Text = "数据库类型";
			// 
			// frmYSJY
			// 
			this.AcceptButton = this.btOK;
			this.AutoScaleBaseSize = new System.Drawing.Size(6, 14);
			this.ClientSize = new System.Drawing.Size(266, 216);
			this.ControlBox = false;
			this.Controls.Add(this.groupBox1);
			this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedToolWindow;
			this.Name = "frmYSJY";
			this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
			this.Text = "配置源数据源";
			this.groupBox1.ResumeLayout(false);
			this.ResumeLayout(false);

		}
		#endregion

		private void cbType_SelectedIndexChanged(object sender, System.EventArgs e)
		{
			tbDBN.Enabled=true;
			if(cbType.Text=="ODBC数据源")
			{
				tbDBN.Enabled=false;
				cbODBC.Visible=true;
				lbODBC.Visible=true;
				lbSql.Visible=false;
				tbSql.Visible=false;
				GetSysODBC(cbODBC.Items);
				return;
			}
			if(cbType.Text=="Access数据库")
			{
				
			}
			if(cbType.Text=="SQLserver数据库")
			{
				lbSql.Visible=true;
				tbSql.Visible=true;
				lbODBC.Visible=false;
				cbODBC.Visible=false;
			}
			if(cbType.Text=="Oracle数据库")
			{
				tbSql.Enabled=false;
				lbSql.Enabled=false;
				cbODBC.Visible=false;
				lbODBC.Visible=false;
			}

			
		}
		private void GetSysODBC(System.Windows.Forms.ComboBox.ObjectCollection slODBC)
		{
			RegistryKey a=Registry.CurrentUser;
			RegistryKey b=a.OpenSubKey("Software");
			RegistryKey c=b.OpenSubKey("ODBC");
			RegistryKey d=c.OpenSubKey("ODBC.INI");
			foreach(string strODBC in d.GetSubKeyNames())
			{	
				slODBC.Add(strODBC);
			}
		}

		private void odbcConnection1_InfoMessage(object sender, System.Data.Odbc.OdbcInfoMessageEventArgs e)
		{
		
		}

		private void btOK_Click(object sender, System.EventArgs e)
		{

			if(cbType.Text=="ODBC数据源")
			{
				if(cbODBC.Text=="")
				{
					MessageBox.Show("Error ****ODBC数据源不能为空!****");
					return;
				}
				strConn="Provider=ODBCOLEDB;DSN="+cbODBC.Text+";"+"UID="+tbUN.Text+";"+"PWD="+tbPW.Text+";";
			}
			else
			{
				if(tbDBN.Text=="")
				{
					MessageBox.Show("Error ****数据库名不能为空!****");
					return;
				}
				if(cbType.Text=="SQLserver数据库")
				{
					strConn="Provider=SQLOLEDB;Data Source="+tbSql.Text+";User ID="+tbUN.Text +";Password="+tbPW.Text+";Initial Catalog="+tbDBN.Text;
				}
				if(cbType.Text=="Access数据库")
				{
					strConn="Provider=Microsoft.Jet.OLEDB.4.0;Data Source="+ tbDBN.Text+ ";User ID="+tbUN.Text+";Password="+tbPW.Text;
					//strConn="Data Source=\""   + tbDBN.Text+  "\";Provider=\"Microsoft.Jet.OLEDB.4.0\";User ID=Admin;Password=;Jet OLEDB:SFP=False;";
				}
				if(cbType.Text=="Oracle数据库")
				{
					strConn="Provider=OraOLEDB.Oracle.1;User ID="+tbUN.Text+";Data Source="+tbDBN.Text+";Persist Security Info=True;Password="+tbPW.Text;
				}
			}
            this.Close();
		}

		private void button1_Click(object sender, System.EventArgs e)
		{
			if(ofd.ShowDialog()==System.Windows.Forms.DialogResult.OK)
				tbDBN.Text=ofd.FileName;
		}



	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -