Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      CodeSOD: Identify a Nap

      September 23, 2025

      Ambient Animations In Web Design: Principles And Implementation (Part 1)

      September 23, 2025

      Benchmarking AI-assisted developers (and their tools) for superior AI governance

      September 23, 2025

      Digital.ai launches White-box Cryptography Agent to enable stronger application security

      September 23, 2025

      Development Release: MX Linux 25 Beta 1

      September 22, 2025

      DistroWatch Weekly, Issue 1140

      September 21, 2025

      Distribution Release: DietPi 9.17

      September 21, 2025

      Development Release: Zorin OS 18 Beta

      September 19, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Stop using .reverse().find(): meet findLast()

      September 23, 2025
      Recent

      Stop using .reverse().find(): meet findLast()

      September 23, 2025

      @ts-ignore is almost always the worst option

      September 22, 2025

      MutativeJS v1.3.0 is out with massive performance gains

      September 22, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      How I Configure Polybar to Customize My Linux Desktop

      September 23, 2025
      Recent

      How I Configure Polybar to Customize My Linux Desktop

      September 23, 2025

      Development Release: MX Linux 25 Beta 1

      September 22, 2025

      DistroWatch Weekly, Issue 1140

      September 21, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»CodeSOD: A Dropped Down DataSet

    CodeSOD: A Dropped Down DataSet

    August 6, 2025

    While I frequently have complaints about over-reliance on Object Relational Mapping tools, they do offer key benefits. For example, mapping each relation in the database to a type in your programming language at least guarantees a bit of type safety in your code. Or, you could be like Nick L‘s predecessor, and write VB code like this.

    <span class="hljs-keyword">For</span> i As Integer = <span class="hljs-number">0</span> <span class="hljs-keyword">To</span> SQLDataset.Tables(<span class="hljs-number">0</span>).Rows.Count - <span class="hljs-number">1</span>
         Try <span class="hljs-comment">'Handles DBNull</span>
             <span class="hljs-keyword">Select</span> <span class="hljs-keyword">Case</span> SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">0</span>)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Bently"</span> <span class="hljs-comment">'Probes</span>
                     Probes_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Keyphasor"</span>
                     Keyphasor_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Transmitter"</span>
                     Transmitter_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Tachometer"</span>
                     Tachometer_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim.ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Dial Therm"</span>
                     DialThermometer_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"DPS"</span>
                     DPS_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Pump Bracket"</span>
                     PumpBracket_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Accelerometer"</span>
                     Accelerometer_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
                 <span class="hljs-keyword">Case</span> <span class="hljs-string">"Velometer"</span>
                     Velometer_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim)
             <span class="hljs-keyword">End</span> <span class="hljs-keyword">Select</span>
         Catch
             <span class="hljs-comment">'MessageBox.Show(text:="Error during SetModelNums().", _</span>
             <span class="hljs-comment">'                caption:="Error", _</span>
             <span class="hljs-comment">'                buttons:=MessageBoxButtons.OK, _</span>
             <span class="hljs-comment">'                icon:=MessageBoxIcon.Error)</span>
         <span class="hljs-keyword">End</span> Try
    <span class="hljs-keyword">Next</span>
    

    So, for starters, they’re using the ADO .Net DataSet object. This is specifically meant to be a disconnected, in-memory model of the database. The idea is that you might run a set of queries, store the results in a DataSet, and interact with the data entirely in memory after that point. The resulting DataSet will model all the tables and constraints you’ve pulled in (or allow you to define your own in memory).

    One of the things that the DataSet tracks is the names of tables. So, the fact that they go and access .Table(0) is a nuisance- they could have used the name of the table. And while that might have been awfully verbose, there’s nothing stopping them from doing DataTable products = SQLDataSet.Tables("Products").

    None of this is what caught Nick’s attention, though. You see, the DataTable in the DataSet will do its best to map database fields to .NET types. So it’s the chain of calls at the end of most every field that caught Nick’s eye:

    SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim
    

    ToUpper works because the field in the database is a string field. Also, it returns a string, so there’s no need to ToString it before trimming. Of course, it’s the Tachometer entry that brings this to its natural absurdity:

    Tachometer_Combobox.Items.Add(SQLDataset.Tables(<span class="hljs-number">0</span>).Rows(i).Item(<span class="hljs-number">1</span>).ToUpper.ToString.Trim.ToUpper.ToString.Trim)
    

    All of this is wrapped up in an exception handler, not because of the risk of an error connecting to the database (the DataSet is disconnected after all), but because of the risk of null values, as the comment helpfully states.

    We can see that once, this exception handler displayed a message box, but that has since been commented out, presumably because there are a lot of nulls and the number of message boxes the users had to click through were cumbersome. Now, the exception handler doesn’t actually check what kind of exception we get, and just assumes the only thing that could happen was a null value. But that’s not true- someone changed one of the tables to add a column to the front, which meant Item(1) was no longer grabbing the field the code expects, breaking the population of the Pump Bracket combo box. There was no indication that this had happened beyond users asking, “Why are there no pump brackets anymore?”

    [Advertisement] Plan Your .NET 9 Migration with Confidence
    Your journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleSimplified Batch Job Creation with Laravel’s Enhanced Artisan Command
    Next Article Telegraph – Morse translator

    Related Posts

    News & Updates

    Development Release: MX Linux 25 Beta 1

    September 22, 2025
    News & Updates

    DistroWatch Weekly, Issue 1140

    September 21, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    Google Fined $379 Million by French Regulator for Cookie Consent Violations

    Development

    Enhancing Business Operations with AI-Driven Automation Solutions

    Web Development

    No-code data preparation for time series forecasting using Amazon SageMaker Canvas

    Machine Learning

    CVE-2025-52903 – Apache File Browser Command Execution Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Highlights

    CodeSOD: Using the Old Bean

    June 19, 2025

    If you write a lot of Java, you’re going to end up writing a lot…

    CVE-2025-33112 – IBM AIX VIOS Perl Path Traversal Vulnerability

    June 11, 2025

    Thunderbird 142 Lets You Add Signatures to PDFs In-App

    August 26, 2025

    CVE-2024-55595 – Cisco Webex Meeting Server Unvalidated Redirect

    June 10, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.