[英]read data from ODBC using DataSet
I have created ODBS user DNS for database, opened VS, created DataSet and imported one table members
. 我已经为数据库创建了ODBS用户DNS,打开了VS,创建了DataSet并导入了一个表
members
。 I would like to read all records from dataset, how to do that? 我想从数据集中读取所有记录,该怎么做? I have tried query below but it return no result.
我在下面尝试过查询,但未返回任何结果。 I can preview data using preview menu in designer but do not find a way to get data using code.
我可以使用设计器中的预览菜单来预览数据,但是找不到使用代码获取数据的方法。
var dataSet = new DataSet1();
var membersDataTable = dataSet.members;
var take = membersDataTable.Take(100);
It looks like you have created the schema for a DataSet, but you have not run any queries to load the DataSet . 看起来您已经为DataSet创建了架构,但是您没有运行任何查询来加载 DataSet 。
using (OdbcConnection connection =
new OdbcConnection(connectionString))
{
string queryString = "SELECT * FROM Members";
OdbcDataAdapter adapter =
new OdbcDataAdapter(queryString, connection);
// Open the connection and fill the DataSet.
try
{
connection.Open();
adapter.Fill(dataSet);
}
catch (Exception ex)
{
Console.WriteLine(ex.Message);
}
// The connection is automatically closed when the
// code exits the using block.
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.