Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
GetAllData() for custom domain-table
Message
De
08/12/2008 15:55:02
Timothy Bryan
Sharpline Consultants
Conroe, Texas, États-Unis
 
 
À
08/12/2008 11:13:51
León Carpay
Carpay Automatisering
Pays-Bas
Information générale
Forum:
ASP.NET
Catégorie:
The Mere Mortals .NET Framework
Versions des environnements
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Divers
Thread ID:
01365978
Message ID:
01366078
Vues:
12
Leon,

>Hi, I'm looking for a way to retireve a subset from a sql-table. I have several key-value fields in the application which I store in one table. When I want to use the DataGridView in combination with a ComboBox I have to bind the ComboBox with a DataTable. MM doesn't support an overload for the GetAllData() method. I designed the (test) method below in the DomainRef class to populate the comboboxes. It works but I think there has to be better ways...
>
>
>        public DataTable GetAllData2(int DomainID)
>        {
>            string cnStr;
>
>            cnStr = mmAppBase.DatabaseMgr.GetConnectionString("BinaDB");
>            using (SqlConnection cn = new SqlConnection(cnStr))
>            {
>                SqlCommand cmd = new SqlCommand("SELECT * FROM DomainRef WHERE DomainID = "  + DomainID.ToString() , cn);
>                SqlDataAdapter adpt = new SqlDataAdapter(cmd);
>                DataTable dtStuff = new DataTable("stuff");
>                adpt.Fill(dtStuff);
>                return dtStuff;
>            }
>        }
>
You should just create additional methods in your business object to get the data you want. GetAllData is only for when you litteraly want to Get All Data which shouldn't be that often.
/// Returns an Entity List
public mmBindingList<DomainRefEntity> GetDomainRefByDomainID(int domainID)
{
     mmBindingList<DomainRefEntity> domainRefList;

     domainRefList = this.GetEntityList("SELECT * FROM DomainRef WHERE DomainID = @DomainID",
          this.CreateParameter("@DomainID", domainID.ToString()));

     return domainRefList;
}
If you want to return a DataSet or DataTable you can do that by calling the proper method on the business object base class also.
public DataSet GetDomainRefByDomainID(int domainID)
{
    return this.GetDataSet("SELECT * FROM DomainRef WHERE DomainID = @DomainID",
          this.CreateParameter("@DomainID", domainID.ToString()));
}
You do not need to create a connection and all that; the framework already does that for you much better.
Tim
Timothy Bryan
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform