
A Simple SELECT
The select is SELECT * FROM users. This means I'm selecting everything (*) from the users table. Pretty straight forward. Beneath the query you can see the results. Further below you can see the time it took to execute the query (the window cuts it off in my screenshot though), the server, the version, the user I'm logged in as, the database and the number of rows retured. Easy, right? It's also bad form.
When pulling database results in a web application using OleDbDataReader, you have to reference your columns by their number. IE, for this query, in order to reference the lastName field, I would use dr.GetValue(4). You may be wondering "so what?". Well, what happens if I add a new column to this table, say a middle name column, and I place it between firstName and lastName? Suddenly dr.GetValue(4) isn't the last name any more. It's the middle name. And you just broke your web application.
edit 29July2010: Please note that you do NOT have to us dr.GetValue(#) to retrieve a column value. You can also pull a column via dr["columnName"]. This would bypass the whole problem with numbered columns, as well as make it easier to go back and read your code. However, you still shouldn't use a splat(*). Always select only the fields you need by manually specifying the column names. Even if you really want all fields from the table, specify the field names anyway.








