简体   繁体   English

从SqlDataAdapter扩展DataSet类填充

[英]Extend DataSet Class Fill From SqlDataAdapter

class InspectionEquip : DataSet
{
    private readonly SqlConnection CPEC = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());

    public InspectionEquip(string store)
    {
        CPEC.Open();
        SqlCommand comm = new SqlCommand("Select * From Equip3 Where Store = '" + store + "'", CPEC);
        SqlDataAdapter da = new SqlDataAdapter(comm);
        da.Fill(/* What to Put Here? Tried "this" and it just returns blank */);    
        CPEC.Close();
    }
}

You have a problem with your SQL query ( no matching data, bad parameter ). 您的SQL查询有问题( 没有匹配的数据,参数错误 )。 da.Fill(this) works fine. da.Fill(this)正常工作。

If you want proof - swap this SqlCommand line with yours... 如果您想证明-将SqlCommand行与您的交换...

SqlCommand comm = new SqlCommand("select * from INFORMATION_SCHEMA.COLUMNS", CPEC);

You should also probably extend DataTable , not DataSet if you only ever plan on storing a single tables results. 如果您仅计划存储单个表结果,则还应该扩展DataTable而不是DataSet

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM