使用SQL(SMO)时如何获取数据集 [英] How to obtain dataset when using SQL(SMO)

查看:82
本文介绍了使用SQL(SMO)时如何获取数据集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


在C#中使用SQL(SMO)时如何获取数据集?
我想将此数据集绑定到DataGridView.

我的用处:

Hi,
How to obtain DataSet when using SQL(SMO) in C#?
I want to bind this DataSet to a DataGridView.

My usings:

using Microsoft.SqlServer.Management.Smo;
using Microsoft.SqlServer.Management.Common;



我的变量:



My variables:

Microsoft.SqlServer.Management.Smo.Server server;
Database db;
Table table;



我的一些代码:



Some of my codes:

//default: @"Integrated Security=SSPI; Data Source=(local)\SQLEXPRESS"
string connectionString = textBoxConnectionString.Text;

SqlConnection serverConnection = new SqlConnection(connectionString);
server = new Server(new ServerConnection(serverConnection));


db = server.Databases[textBoxDatabase.Text];

推荐答案

据我所知,这是不可能的.

SMO代表SQLServer管理对象,在这方面非常擅长-管理SQLServer.它既不是为访问或编辑数据而设计的,也不应该用于此目的.

如果您想允许您的用户选择要访问的数据库,那么SMO将是您的理想之选.选择它们之后,您应该使用标准SQLClient类以及所选数据库的名称.
To the best of my knowledge, this is not possible.

SMO stands for SQLServer Management Objects and it is very good at that - Managing SQLServer. It was not designed for accessing nor editing data and should not be used for that.

If you wanted to allow your user(s) to select which database to access, then SMO would be the way to go. Once they have chosen you should use the standard SQLClient classes using the name of the database chosen.


这篇关于使用SQL(SMO)时如何获取数据集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆