Comparing 2 Values

elais12

Member
Joined
Jul 20, 2018
Messages
7
Programming Experience
Beginner
Hi together

I developed a litte programm which does following:

It subctrats the open bills from the salary and calculate a daily limit
Now i do a Subselect (see code snippet below) to get 2 Values from 2 Tables in SQL Database
(dbo.Limiten and dbo.Ausgaben)

C#:
 private void Alarm_Click(object sender, EventArgs e)
        {
            OleDbConnection con = new OleDbConnection();
            OleDbCommand cmd = new OleDbCommand();
            OleDbDataReader reader;
            con.ConnectionString = "Provider=SQLNCLI11.1;" + "Data Source=CRONOS-WI764BIT;Initial Catalog=Tageslimit;Persist Security Info=True;User ID=sa;Password=satest$";
            cmd.Connection = con;
            // Limite abzüglich Summe der Ausgaben ergibt Differenz die bei Ueberschreitung rotes Label anzeigt
            cmd.CommandText = "Select (Select (Nettolohn - Zahlungen) / 30  As Resultat from Limiten) - (Select SUM(Preis) AS Summe from Ausgaben) AS Differenz from Ausgaben";
            try
            {
                con.Open();
                reader = cmd.ExecuteReader();
                LstAnzeige3.Items.Clear(); // Liste leeren
                while (reader.Read())  // Der Zugriff auf die DB geht solange bis der letzte Datensatz erreicht wurde
                {
                    LstAnzeige3.Items.Add("Tageslimite abzüglich Summe der Ausgabe pro Tag    " + reader["Differenz"]);
                    

                }
                reader.Close(); // "Reader" schliessen
                con.Close(); // dasselbe mit der Verbindung zur DB
            }
            catch (Exception ex) // gibts ein Problem?
            {
                MessageBox.Show(ex.Message); // dann Fehlermeldung ausgeben
            }

How can i do a compare, so if the total of all "Ausgaben" is higher than the daily limit
for example if the limit exeeced the total

Hope i have explained good cause my english is not so good..
 
You will need to get the two values out of the database and stored into numeric variables, depending on how it comes out of the database you might have to convert them to numeric data types but once you have that it's a simple is one larger than the other and go from there.
 
Hello JuggaloBrotha

Thanks for your Reply. This was the hint. I defined two Variables and now the comparing works fine :)
 
Back
Top Bottom