您的位置:首页 > 编程语言 > VB

直接调用内置数据源连接对话框(C#/VB.NET2005源码)

2006-12-22 09:04 721 查看
直接调用内置数据源连接对话框(C#/VB.NET2005源码)

'先引用Microsoft.Data.ConnectionUI.Dialog.dll(在VS2005安装路径的IDE目录下)
VB:


Dim dialog As DataConnectionDialog = New DataConnectionDialog()


dialog.DataSources.Add(DataSource.SqlDataSource)


dialog.DataSources.Add(DataSource.OdbcDataSource)


dialog.DataSources.Add(DataSource.OracleDataSource)


dialog.DataSources.Add(DataSource.AccessDataSource)




dialog.SelectedDataSource = DataSource.SqlDataSource


dialog.SelectedDataProvider = DataProvider.SqlDataProvider




DataConnectionDialog.Show(dialog)


If dialog.DialogResult = Windows.Forms.DialogResult.OK Then


Me.TextBox1.Text = dialog.ConnectionString


ElseIf dialog.DialogResult = Windows.Forms.DialogResult.Cancel Then


Me.Close()


End If

C#2005 Code

DataConnectionDialog dialog = new DataConnectionDialog();
dialog.DataSources.Add(DataSource.SqlDataSource);
dialog.DataSources.Add(DataSource.OdbcDataSource);
dialog.DataSources.Add(DataSource.OracleDataSource);
dialog.DataSources.Add(DataSource.AccessDataSource);

dialog.SelectedDataSource = DataSource.SqlDataSource;
dialog.SelectedDataProvider = DataProvider.SqlDataProvider;

string strCon = "";
DataConnectionDialog.Show(dialog);
if (dialog.DialogResult == DialogResult.OK)
{ strCon = dialog.ConnectionString; }
else if (dialog.DialogResult == DialogResult.Cancel)
{ }

MessageBox.Show(strCon);

来自:/article/5546611.html
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐