Comparison of database dates with system date

Asked

Viewed 100 times

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 register in a column the number for the month. For example:

On 12/16/2016 I registered a product, the table contains the product name, 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();

Therefore, if in December I registered 10 products with price of 10 real accurate that the system compare the column 'month' of the database with the month of the computer, realize the sum of the values of the column 'price' whose row is the month in question.

1 answer

2


From what I understand, you want the bank value for the c#, right?

Then follows a code illustrating how to return from the bank 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 sum value will be stored in the property Text of control ValorTotal.
The form of connection to the bank was just an example.

  • I modified it according to my code and it worked! Thanks!

Browser other questions tagged

You are not signed in. Login or sign up in order to post.