从SQL表中检索DataSet

时间:2013-12-23 20:50:48

标签: c# sql database

static public DataSet GetDataSet(string strSql)
{
    DataSet ds = new  DataSet();
    SqlConnection connection = new SqlConnection(DAL.ConnectionString);
    SqlCommand command = new SqlCommand(strSql, connection);
    SqlDataAdapter dataAdapter = new SqlDataAdapter(command);
    dataAdapter.Fill(ds);
    return ds;
}

这是我用来检索数据集的代码,我得到对象名称(certin表)未知的错误。该路径应该有效:

static private string path;
//static private string connectionString;
static public string Path
{
    set
    {
        DAL.path = value;
    }
    get
    {
        return DAL.path;
    }           
}

static private string ConnectionString
{
    get
    {
        return string.Format(@"Data Source=.\SQLEXPRESS;AttachDbFilename={0};Integrated Security=True;User Instance=True", DAL.Path);
    }
}

如果我能在接下来的几天里为学校项目寻求帮助,那真的很棒。

1 个答案:

答案 0 :(得分:0)

请确保在SQL查询中使用了正确的表名。

SQL查询和附加数据库中的表名应该相同。