Show Count of a Query in a Label

0

How about, I'm trying to show the result of a query in which I count the results depending on where

my query is in a folder called conexiones and inside it has a class called conexion-general in that class I made the query in this way:

public class conteo_maint
    {
        public DataTable countconnect()
        {
            string myConnectionString = @"C:\Users\gutiece\Desktop\database\" + "Database1.accdb";

            DataTable CouMaiTable = new DataTable();

            OleDbConnection connection = new OleDbConnection();
            OleDbCommand command = new OleDbCommand();
            OleDbDataAdapter adapter = new OleDbDataAdapter();
            DataSet dataset = new DataSet();

            try
            {
                connection.ConnectionString = @"Provider=Microsoft.ACE.OLEDB.12.0; Data source= " + myConnectionString;
                bool ok = System.IO.File.Exists(myConnectionString);
                String qry = "SELECT COUNT(*) FROM status_change WHERE area = maintenance";
                String allqry = "SELECT * FROM status_change WHERE area = maintenance";
                command.Connection = connection;
                command.CommandText = qry;
                command.CommandText = allqry;

                adapter.SelectCommand = command;

                command.Connection.Open();
                OleDbDataReader reader = command.ExecuteReader(); // close conn after 
                CouMaiTable.Load(reader);
                if (!reader.IsClosed)
                {
                    reader.Close();
                }

                return CouMaiTable;
            }
            catch (Exception)
            {
            }
            return CouMaiTable;
        }
    }

I have the two queries so that only one shows the total and the other can fill a GridView .

Then I have dashboard.aspx in which is where I want to show the result of count . in the Backend command to call the case of conteo_maint in this way:

conexiones.conteo_maint countconnect = new conexiones.conteo_maint();
conexiones.conteo_maint CouMaiTable = new conexiones.conteo_maint();

and I want the count result to be shown in this label :

<button class="btn btn-primary" type="button">
                  Messages <span class="badge">
                      <asp:Label Text="text" runat="server"  id="Lbl_notu"/></span>
                </button>&nbsp

    
asked by Cesar Gutierrez Davalos 06.06.2017 в 15:54
source

1 answer

0

You do not need to do two queries . Simply with the allqry you would have enough.

Returning this, then in your code-behind of dashboard.aspx , just do a

Lbl_notu.Text = CouMaiTable.Rows.Count and it will tell you how many rows it has.

    
answered by 08.06.2017 в 16:55