这是我的代码:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.SessionState;
//db con
using System.Data;
using System.Data.OleDb;
using System.Data.SqlClient;
using System.Configuration;
namespace SOMaintenance.App_Code {
public class readdata {
string sConnectionString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
public void selectdata(DataSet dataset1, string sqlcommand) {
string strConString = ConfigurationManager.ConnectionStrings["SOConnectionString"].ConnectionString;
OleDbConnection conn = new OleDbConnection(strConString);
OleDbCommand cmd = new OleDbCommand("SELECT * FROM USERMASTER", conn);
cmd.Fill(dataset1);
conn.Open();
OleDbDataReader dr;
}
}
}
我想知道为什么cmd.Fill(dataset1);
无法使用。它告诉我添加system.data.oledb.command
但是当我添加问题时仍然是这样。
任何人都可以帮忙吗?
答案 0 :(得分:0)
试试这个:
DataTable dataTable = new DataTable("USERMASTER");
using (var conn = new OleDbConnection(sConnectionString))
{
conn.Open();
var queryString = "SELECT * FROM USERMASTER";
using (var comm = new OleDbCommand(queryString, conn))
{
using (OleDbDataAdapter da = new OleDbDataAdapter (comm))
{
da.Fill(dataTable);
return dataTable;
}
}
conn.Close();
}