Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
GetAllData() for custom domain-table
Message
From
08/12/2008 15:55:02
Timothy Bryan
Sharpline Consultants
Conroe, Texas, United States
 
 
To
08/12/2008 11:13:51
León Carpay
Carpay Automatisering
Netherlands
General information
Forum:
ASP.NET
Category:
The Mere Mortals .NET Framework
Environment versions
Environment:
C# 3.0
OS:
Windows XP SP2
Network:
Windows 2008 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01365978
Message ID:
01366078
Views:
11
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
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform