Monday, November 07, 2005

doh! of the day

Holy crap.  I can’t believe I wasted 45 minutes on this stupid, stupid, mistake.

When dealing with .NET and IDbCommands, you can execute the command in various ways:

  • ExecuteReader() – which will execute the command and return an IDataReader with the resultset loaded.
  • ExecuteScalar() – which will return a single value from the database, generally used for returning a COUNT or an @@IDENTITY
  • ExecuteNonQuery() – which is used for, well, just plain executing a query.  This function DOES have a return value, though:  the number of records affected.

I just spent almost an hour trying to figure out why this:

//Execute command and return the primary key of the item we just inserted
base
._id = Convert.ToInt32(cmd.ExecuteNonQuery());

was returning 1, always, even though the current primary key in that table is in the 90’s.

Looks like I need to get some sleep…

Now playing: Staind - Mudshovel - Winamp *** 1514. Staind - Mudshovel

Credit Counseling - Wills - Loan - Debt