Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/330.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 使用asp.net c返回有效的数据集_C#_Asp.net_Webforms_Data Access Layer_Bll - Fatal编程技术网

C# 使用asp.net c返回有效的数据集

C# 使用asp.net c返回有效的数据集,c#,asp.net,webforms,data-access-layer,bll,C#,Asp.net,Webforms,Data Access Layer,Bll,当我从下拉列表中选择一个值时,我不断收到一个错误 **在调用“填充”之前,SelectCommand属性尚未初始化** 看起来我的数据集返回为空 我想坚持三层结构 如何使用代码返回有效的数据集 达尔 BLL 看起来我下面有一些多余的代码。我想使用下面的连接类: public DataSet returnCustomer(collection b) { try { SqlDataAdapter adapt = new SqlDataAd

当我从下拉列表中选择一个值时,我不断收到一个错误

**在调用“填充”之前,SelectCommand属性尚未初始化**

看起来我的数据集返回为空

我想坚持三层结构

如何使用代码返回有效的数据集

达尔

BLL

看起来我下面有一些多余的代码。我想使用下面的连接类:

   public DataSet returnCustomer(collection b)
   {
       try
       {
           SqlDataAdapter adapt = new SqlDataAdapter();
           DataSet table = new DataSet();

           adapt.Fill(table, "table");
           return table;
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }
连接类

PL


根据我在对OP问题的评论中提到的假设,您需要遵循以下步骤

将DAL更改为具有此公共静态数据表GetCustomerstring customer_ref,并使用此DB.AddInParameterDBCommand、@CustomerRef、DbType.String、customer_ref

我看到在BAL中没有完成任何工作,所以我跳过了它的使用

不要在bobj中使用BLL对象,而是使用DAL实例中的一个,因为它有GetCustomer,并且有一些工作可以从DB中获取信息


假设bobj是DAL的一个实例,接下来,更改PL,如下-txtCustomerRef.Text=bobj.GetCustomerselectedValue.Tables[0]。行[0][0]。ToString

如下更改DAL代码:

public static DataTable GetCustomer(collection b)
{
    {
        DataTable table = new DataTable();
        try
        {
            string returnValue = string.Empty;
            DB = Connect();
            DBCommand = connection.Procedure("getCustomer");
            DB.AddInParameter(DBCommand, "@CustomerRef", DbType.String, b.CustomerRef1);

            SqlDataAdapter adptr = new SqlDataAdapter(DBCommand);
            adptr.Fill(table);
            return table;
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
}
现在你的BAL是这样的

public DataSet returnCustomer(collection b)
   {
       try
       {
           DataSet _ds = new DataSet();
           _ds.Tables.Add(DAL.GetCustomer(b));
           return _ds;
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }

在returnCustomer方法中,dataadapter中没有任何命令。所以,它是空的。添加了连接类*我想,BLL代码缺少了一些东西,什么都不做,我的意思是,你需要一些命令对象来填充它,或者查询DAL,获取一些值,基于业务逻辑应用过滤器,然后返回对象,如果您仅在GetCustomer中需要CustomerRef1,则可以直接传递字符串。我需要最终获得客户名称、客户地址等。如果您能告诉我并回答,这将很好。。我整日整夜都在努力解决这个问题:无法从'System.Data.Common.DbCommand'转换为'System.Data.SqlClient.SqlCommand'与'System.Data.SqlClient.SqlDataAdapter.SqlDataAdapterSystem.Data.SqlClient.SqlCommand'最匹配的重载方法是'System.Data.SqlClient.SqlCommand'有一些无效的参数我也愿意接受你的答案。谢谢,但我看不到GetCustomer从我的PLB来看,这就是为什么我写了一篇文章,将bobj作为DAL的一个实例,而不是BLLI创建的DAL.collection dobj=new collection;我仍然看不到GetCustomerI无法帮助您,直到我在LIVE中看到您的解决方案,您需要以下训练:。
protected void ddl_Customers_SelectedIndexChanged(object sender, EventArgs e)
{

    DAL.collection cobj = new collection();
    BLL.business bobj = new business();

    string selectedValue = ddl_Customers.SelectedValue.ToString();

        //populate the text boxes
        txtCustomerRef.Text = bobj.returnCustomer(cobj).Tables[0].Rows[0][0].ToString();
}
public static DataTable GetCustomer(collection b)
{
    {
        DataTable table = new DataTable();
        try
        {
            string returnValue = string.Empty;
            DB = Connect();
            DBCommand = connection.Procedure("getCustomer");
            DB.AddInParameter(DBCommand, "@CustomerRef", DbType.String, b.CustomerRef1);

            SqlDataAdapter adptr = new SqlDataAdapter(DBCommand);
            adptr.Fill(table);
            return table;
        }
        catch (Exception ex)
        {
            throw (ex);
        }
    }
}
public DataSet returnCustomer(collection b)
   {
       try
       {
           DataSet _ds = new DataSet();
           _ds.Tables.Add(DAL.GetCustomer(b));
           return _ds;
       }
       catch (Exception ex)
       {
           throw ex;
       }
   }