1个回答
2014-07-29
展开全部
你的数据库连接在哪里呢?你看我写的代码实例,请参考,希望能帮助到你
private static readonly string _connectionString;
public DataTable GetAll()
{
// Initialize the DataAdapter
SqlDataAdapter dad = new SqlDataAdapter("SELECT Title,Director FROM Movies", _connectionString);
// Create a DataTable
DataTable dtblMovies = new DataTable();
// Populate the DataTable
dad.Fill(dtblMovies);
// Return results
return dtblMovies;
}
static Movie8()
{
_connectionString = WebConfigurationManager.ConnectionStrings["Movies"].ConnectionString;
}
private static readonly string _connectionString;
public DataTable GetAll()
{
// Initialize the DataAdapter
SqlDataAdapter dad = new SqlDataAdapter("SELECT Title,Director FROM Movies", _connectionString);
// Create a DataTable
DataTable dtblMovies = new DataTable();
// Populate the DataTable
dad.Fill(dtblMovies);
// Return results
return dtblMovies;
}
static Movie8()
{
_connectionString = WebConfigurationManager.ConnectionStrings["Movies"].ConnectionString;
}
追问
第一条就是连接数据库的,我在dataset里看到数据,就是在前台显示不出来。
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询