Page 1 of 1

Add more queries to a tableadapter

Posted: Wed 09 Dec 2009 18:31
by jebus_jt
Is there anyway to add more queries to a tableadapter? for example I need a query that returns a table as a result of a select statement that has parameters, but in the same tableadapter I need a query (other select statement) that counts how many rows are in the table...Of course I know how the select statements are going to be, but I don't know if there is a way to add another query.

thanks

Posted: Thu 10 Dec 2009 16:32
by StanislavK
Unfortunately, the design-time support of multiple queries for TableAdapter is not available now. We will consider the possibility of adding such functionality in one of the future dotConnect for PostgreSQL versions.

At the moment you can add more queries e.g. to the custom DataTable class. Thus, if you've generated a custom DataSet class CustomDataSet and corresponding DataTable class CustomDataSet.CustomDataTable, it will be something like

Code: Select all

using Devart.Data.PostgreSql;

namespace YourApplicationNamespace
{
    public partial class CustomDataSet
    {
        public partial class CustomDataTable
        {
            public decimal getCount()
            {
                PgSqlCommand command = new PgSqlCommand(
                    "select count(*) from Your_Table", Connection);

                try
                {
                    if (Connection.State !=System.Data.ConnectionState.Open) 
                        Connection.Open();
                    object ret = command.ExecuteScalar();                    
                    return (decimal)ret;
                }
                catch
                {
                    return -1;
                }
                finally
                {
                    Connection.Close();                  
                }                
            }
        }
    }
}

Posted: Thu 10 Dec 2009 16:42
by jebus_jt
ok thanks.
well I've been trying some ways to do that, and I found a solution, maybe it is not the best way to do it but works. What I did was just open the dataset that I created with the Dataset Wizard and I just added a new query in the tableadapter using .NET Wizard for adding queries, and it worked great.

And since I found that way to add queries, I just edit the Designer.VB file adding the extra queries I need, it works fine but anyway its a time eater solution, it will be great if you could add this feature.