Computer
Chemical Pollution a Threat Comparable To Climate Change, Scientists Warn
Read more of this story at Slashdot.
Great Barrier Reef Suffers Worst Coral Decline on Record
Read more of this story at Slashdot.
Astronomers Cannot Agree On How Fast the Universe is Expanding
Read more of this story at Slashdot.
Sci-Fi Adaptation War of the Worlds Scores 0% on Rotten Tomatoes
Read more of this story at Slashdot.
Google Says AI Search Features Haven't Hurt Web Traffic Despite Industry Reports
Read more of this story at Slashdot.
Call of Duty's Anti-Cheat Will Require TPM 2.0 and Secure Boot for PC Players
Read more of this story at Slashdot.
Tornado Cash Co-Founder Storm Guilty in Crypto Mixing Case
Read more of this story at Slashdot.
Universal Pictures To Big Tech: We'll Sue If You Steal Our Movies For AI
Read more of this story at Slashdot.
Google Suffers Data Breach in Ongoing Salesforce Data Theft Attacks
Read more of this story at Slashdot.
OpenAI Offers ChatGPT To US Federal Agencies for $1 a Year
Read more of this story at Slashdot.
Trump, Apple To Announce New $100 Billion Commitment To Manufacturing in US
Read more of this story at Slashdot.
Nvidia Rejects US Demand For Backdoors in AI Chips
Read more of this story at Slashdot.
Lyft Will Use Chinese Driverless Cars In Britain and Germany
Read more of this story at Slashdot.
Meta Eavesdropped On Period-Tracker App's Users, Jury Rules
Read more of this story at Slashdot.
NASA Satellites That Scientists and Farmers Rely On May Be Destroyed On Purpose
Read more of this story at Slashdot.
CodeSOD: A Dropped Down DataSet
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.
For i As Integer = 0 To SQLDataset.Tables(0).Rows.Count - 1 Try 'Handles DBNull Select Case SQLDataset.Tables(0).Rows(i).Item(0) Case "Bently" 'Probes Probes_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "Keyphasor" Keyphasor_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "Transmitter" Transmitter_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "Tachometer" Tachometer_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim.ToUpper.ToString.Trim) Case "Dial Therm" DialThermometer_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "DPS" DPS_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "Pump Bracket" PumpBracket_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "Accelerometer" Accelerometer_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) Case "Velometer" Velometer_Combobox.Items.Add(SQLDataset.Tables(0).Rows(i).Item(1).ToUpper.ToString.Trim) End Select Catch 'MessageBox.Show(text:="Error during SetModelNums().", _ ' caption:="Error", _ ' buttons:=MessageBoxButtons.OK, _ ' icon:=MessageBoxIcon.Error) End Try NextSo, 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(0).Rows(i).Item(1).ToUpper.ToString.TrimToUpper 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(0).Rows(i).Item(1).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 ConfidenceYour journey to .NET 9 is more than just one decision.Avoid migration migraines with the advice in this free guide. Download Free Guide Now!
RIP To the Macintosh HD Hard Drive Icon, 2000-2025
Read more of this story at Slashdot.
Jim Acosta Interviews AI Version of Teenager Killed in Parkland Shooting
Read more of this story at Slashdot.
Perplexity Says Cloudflare's Accusations of 'Stealth' AI Scraping Are Based On Embarrassing Errors
Read more of this story at Slashdot.
Swedish PM Under Fire For Using AI In Role
Read more of this story at Slashdot.