Results 1 to 3 of 3

Thread: Comparing 2 Values

  1. #1
    .NET Framework
    .NET 4.5
    Join Date
    Jul 2018
    Posts
    7
    Rep Power
    0

    Comparing 2 Values

    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)

    Code:
     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..

  2. #2
    .NET Framework
    .NET 4.0
    Join Date
    Apr 2011
    Location
    Lansing, MI; USA
    Posts
    140
    Rep Power
    98
    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.
    Currently using VS 2015 Enterprise on Win10 Enterprise x64.

  3. #3
    .NET Framework
    .NET 4.5
    Join Date
    Jul 2018
    Posts
    7
    Rep Power
    0
    Hello JuggaloBrotha

    Thanks for your Reply. This was the hint. I defined two Variables and now the comparing works fine

Similar Threads

  1. Do we convert values just to be more efficient?
    By VitzzViperzz in forum C# General Discussion
    Replies: 2
    Last Post: 02-10-2017, 9:04 AM
  2. Calculated Values
    By BitLost in forum MV*
    Replies: 1
    Last Post: 02-09-2017, 6:44 PM
  3. DataReader - Handling Null Values
    By HLeyes in forum SQL Server
    Replies: 2
    Last Post: 12-01-2016, 7:00 PM
  4. Question initialize dictionary with keys/values
    By old1mike in forum C# General Discussion
    Replies: 3
    Last Post: 09-06-2016, 5:41 AM
  5. duplicate values in HashSet
    By superchat6 in forum C# General Discussion
    Replies: 1
    Last Post: 11-25-2013, 1:07 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •