0

ドロップダウンから値を選択すると、エラーが発生し続けます。

**The SelectCommand property has not been initialized before calling 'Fill'.**

データセットが空として返されているようです。

3層構造にこだわりたい。

コードを使用して有効なデータセットを返すにはどうすればよいですか?

ダル

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

            DbDataReader reader = DBCommand.ExecuteReader();
            table = new DataTable();
            table.Load(reader);
            return table;
        }
        catch (Exception ex)
        {
            throw (ex);
        }

    }

}

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;
       }
   }

接続クラス

using Microsoft.Practices.EnterpriseLibrary.Data;
using Microsoft.Practices.EnterpriseLibrary.Common;
using Microsoft.Practices.ObjectBuilder;
using System.Data.Common;
using System.Data;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAL
{
    public class connection
    {
        const string StrConnection = "CustomerHelperConnectionString";
        internal static Database DB;
        public static DbCommand DBCommand;
        public static Database Connect()
        {

            try
            {
                DB = DatabaseFactory.CreateDatabase(StrConnection);
                return DB;
            }
            catch (Exception ex)
            {
                throw (ex);
            }
        }
        public static DbCommand Procedure(string procedure)
        {

            try
            {
                DBCommand = DB.GetStoredProcCommand(procedure);
                return DBCommand;
            }
            catch (Exception ex)
            {
                throw (ex);            
            }
        }
    }
}

PL

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();
}
4

2 に答える 2

1

OPの質問へのコメントで言及されている私の仮定に従って、あなたは従う必要があります。

これを持つようにDALを変更し、これpublic static DataTable GetCustomer(string customer_ref)を使用しますDB.AddInParameter(DBCommand, "@CustomerRef", DbType.String, customer_ref);

BAL で作業が行われていないことがわかったので、その使用をスキップしています。

BLL オブジェクトを使用する代わりにbobj、DAL インスタンスの 1 つを使用します。これにはGetCustomer、DB から情報を取得するための作業があります。

したがってbobj、DAL のインスタンスであると仮定すると、次のように PL を変更します。txtCustomerRef.Text = bobj.GetCustomer(selectedValue).Tables[0].Rows[0][0].ToString();

于 2015-04-19T11:21:03.613 に答える