怎样调用oleDB的“数据链接属性”对话框? 我想让用户在使用时动态的配置数据库连接串,所以想调用“数据链接属性”对话框,如果在VC里,直接调用借口的PromptNew方法就可以了,在C#里,我不想调用Com的接口,.net里面有没有提供相同功能的方法或者对象对象? 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 /* * (C) DAN MAYER 2004 * QUESTION OR COMMENTS PLEASE WRITE [email protected] * */using System;using System.Drawing;using System.Collections;using System.ComponentModel;using System.Windows.Forms;using System.Data;namespace OdbcConnect{ public class Form1 : System.Windows.Forms.Form { public System.Windows.Forms.TextBox txtConnectionString; private System.Windows.Forms.Label lbConnectionString; private System.Windows.Forms.Button ButtonGetConnectionString; /// <summary> /// Required designer variable. /// </summary> private System.ComponentModel.Container components = null; public Form1() { // // Required for Windows Form Designer support // InitializeComponent(); } /// <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.txtConnectionString = new System.Windows.Forms.TextBox(); this.lbConnectionString = new System.Windows.Forms.Label(); this.ButtonGetConnectionString = new System.Windows.Forms.Button(); this.SuspendLayout(); // // txtConnectionString // this.txtConnectionString.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left) | System.Windows.Forms.AnchorStyles.Right))); this.txtConnectionString.Location = new System.Drawing.Point(16, 32); this.txtConnectionString.Name = "txtConnectionString"; this.txtConnectionString.Size = new System.Drawing.Size(232, 20); this.txtConnectionString.TabIndex = 18; this.txtConnectionString.Text = ""; // // lbConnectionString // this.lbConnectionString.AutoSize = true; this.lbConnectionString.Location = new System.Drawing.Point(16, 16); this.lbConnectionString.Name = "lbConnectionString"; this.lbConnectionString.Size = new System.Drawing.Size(126, 16); this.lbConnectionString.TabIndex = 17; this.lbConnectionString.Text = "Data source connection:"; // // ButtonGetConnectionString // this.ButtonGetConnectionString.Location = new System.Drawing.Point(248, 32); this.ButtonGetConnectionString.Name = "ButtonGetConnectionString"; this.ButtonGetConnectionString.Size = new System.Drawing.Size(24, 23); this.ButtonGetConnectionString.TabIndex = 19; this.ButtonGetConnectionString.Text = "..."; this.ButtonGetConnectionString.Click += new System.EventHandler(this.ButtonGetConnectionString_Click); // // Form1 // this.AutoScaleBaseSize = new System.Drawing.Size(5, 13); this.ClientSize = new System.Drawing.Size(292, 94); this.Controls.Add(this.ButtonGetConnectionString); this.Controls.Add(this.txtConnectionString); this.Controls.Add(this.lbConnectionString); this.Name = "Form1"; this.Text = "Form1"; this.ResumeLayout(false); } #endregion /// <summary> /// The main entry point for the application. /// </summary> [STAThread] static void Main() { Application.Run(new Form1()); } private void ButtonGetConnectionString_Click(object sender, System.EventArgs e) { /* Reference DataLinks NOTE: Reference C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL (Was MSDASC.dll) SEE: http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp */ MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass(); //note that a reference to: // c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll //is also required to read the ADODB._Connection result ADODB._Connection connection; //are we editing an existing connect string or getting a new one? if(this.txtConnectionString.Text==String.Empty) { // get a new connection string try { //Prompt user for new connect string connection = (ADODB._Connection)dataLinks.PromptNew(); //read result this.txtConnectionString.Text=connection.ConnectionString.ToString(); } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } else { // edit connection string connection=new ADODB.ConnectionClass(); connection.ConnectionString=this.txtConnectionString.Text; //set local COM compatible data type object oConnection=connection; try { //prompt user to edit the given connect string if((bool)dataLinks.PromptEdit(ref oConnection)) { this.txtConnectionString.Text=connection.ConnectionString; } } catch(Exception ex) { MessageBox.Show(ex.ToString()); } } } }} http://www.cnblogs.com/lichdr/archive/2004/10/20/54568.html winform中如何读取普通文件按exe执行呢 Oracle 日期转换问题 谁能帮我写个函数 cpu Time = processes[i].TotalProcessorTime拒绝访问 关于继承的一个简单的问题 算法问题 各位大侠快来看 关于c#线程的问题。 正好整理了一下,自己做了个连接数据库的组件,支持SQLSERVER,ACCESS,ORACLE,FoxPro,MySql,IBM DB2,DBF等数据库,并且支持事务处理 换了上网方式,现在可以全天上网,高兴,散分 请问真正有经验专家,.Net有多广的应用面? 这个正则表示什么意思? 请问:ADO.net中能不能给SQL语句传参数呢?
* (C) DAN MAYER 2004
* QUESTION OR COMMENTS PLEASE WRITE [email protected]
* */
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;namespace OdbcConnect
{
public class Form1 : System.Windows.Forms.Form
{
public System.Windows.Forms.TextBox txtConnectionString;
private System.Windows.Forms.Label lbConnectionString;
private System.Windows.Forms.Button ButtonGetConnectionString;
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.Container components = null; public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();
} /// <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.txtConnectionString = new System.Windows.Forms.TextBox();
this.lbConnectionString = new System.Windows.Forms.Label();
this.ButtonGetConnectionString = new System.Windows.Forms.Button();
this.SuspendLayout();
//
// txtConnectionString
//
this.txtConnectionString.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.txtConnectionString.Location = new System.Drawing.Point(16, 32);
this.txtConnectionString.Name = "txtConnectionString";
this.txtConnectionString.Size = new System.Drawing.Size(232, 20);
this.txtConnectionString.TabIndex = 18;
this.txtConnectionString.Text = "";
//
// lbConnectionString
//
this.lbConnectionString.AutoSize = true;
this.lbConnectionString.Location = new System.Drawing.Point(16, 16);
this.lbConnectionString.Name = "lbConnectionString";
this.lbConnectionString.Size = new System.Drawing.Size(126, 16);
this.lbConnectionString.TabIndex = 17;
this.lbConnectionString.Text = "Data source connection:";
//
// ButtonGetConnectionString
//
this.ButtonGetConnectionString.Location = new System.Drawing.Point(248, 32);
this.ButtonGetConnectionString.Name = "ButtonGetConnectionString";
this.ButtonGetConnectionString.Size = new System.Drawing.Size(24, 23);
this.ButtonGetConnectionString.TabIndex = 19;
this.ButtonGetConnectionString.Text = "...";
this.ButtonGetConnectionString.Click += new System.EventHandler(this.ButtonGetConnectionString_Click);
//
// Form1
//
this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
this.ClientSize = new System.Drawing.Size(292, 94);
this.Controls.Add(this.ButtonGetConnectionString);
this.Controls.Add(this.txtConnectionString);
this.Controls.Add(this.lbConnectionString);
this.Name = "Form1";
this.Text = "Form1";
this.ResumeLayout(false); }
#endregion /// <summary>
/// The main entry point for the application.
/// </summary>
[STAThread]
static void Main()
{
Application.Run(new Form1());
} private void ButtonGetConnectionString_Click(object sender, System.EventArgs e)
{
/*
Reference DataLinks
NOTE: Reference
C:\Program Files\Common Files\System\Ole DB\OLEDB32.DLL
(Was MSDASC.dll)
SEE:
http://support.microsoft.com:80/support/kb/articles/Q225/1/32.asp
*/
MSDASC.DataLinks dataLinks = new MSDASC.DataLinksClass();
//note that a reference to:
// c:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll
//is also required to read the ADODB._Connection result
ADODB._Connection connection;
//are we editing an existing connect string or getting a new one?
if(this.txtConnectionString.Text==String.Empty)
{
// get a new connection string
try
{
//Prompt user for new connect string
connection = (ADODB._Connection)dataLinks.PromptNew();
//read result
this.txtConnectionString.Text=connection.ConnectionString.ToString();
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
else
{
// edit connection string
connection=new ADODB.ConnectionClass();
connection.ConnectionString=this.txtConnectionString.Text;
//set local COM compatible data type
object oConnection=connection;
try
{
//prompt user to edit the given connect string
if((bool)dataLinks.PromptEdit(ref oConnection))
{
this.txtConnectionString.Text=connection.ConnectionString;
}
}
catch(Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
}
}
}