Comparison of database dates with system date

0

Hello

I need to compare the month of registration of information present in a database table with the current month provided by the system.

In the database I enter the number for the month in a column. For example:

On 16/12/2016 I registered a product, the table includes the name of the product, price and number of the month. I need to add the values of the products of the current month, that is, the prices of the products of the month provided by the system through this code:

string mes = DateTime.Now.Month.ToString();

So if in December I registered 10 products with a price of 10 reais, I need the system to compare the month column of the database with the month of the computer, make the sum of the values of the column 'price' whose line be the month in question.

    
asked by anonymous 17.12.2016 / 17:59

1 answer

2

From what I understand, you want the bank's value for C #, right?

Then follows a code illustrating how to return from the database the sum of all products of the month returned by the system.

string mes = DateTime.Now.Month.ToString();
string pesquisa = "SELECT SUM(Preco) FROM PRODUTOS WHERE MES = " + mes;
using (System.Data.IDbCommand comando = new System.Data.OleDb.OleDbCommand(pesquisa, DBconn))
{
   object resultado = comando.ExecuteScalar();
   ValorTotal.Text = Convert.ToString(resultado);
}

The summed value will be stored in the Text property of the ValorTotal control. The way to connect to the bank was just an example.

    
20.12.2016 / 19:06