Carl’s Geek Notes

December 8, 2008

Run a SQL UPDATE command and return the number of affected records

Filed under: C#/.NET, Computers, Programming, SQL Server — Tags: , , — Carl @ 9:29 am

I wanted a quick way to run a SQL UPDATE command and return the number of affected rows in .NET.  Here’s the code to do it:

int RecordCount = 0;
string SQL = "UPDATE MyTable SET MyField = @MyNewValue "
    + "WHERE MyKey = @MyKey "
    + "SET @RecordCount = @@ROWCOUNT";
SqlCommand MyCmd = new SqlCommand(SQL, MyConn);

// Use an out parameter to get the number of rows affected
SqlParameter RecordCountParam = new SqlParameter("@RecordCount", SqlDbType.Int);
RecordCountParam.Direction = ParameterDirection.Output;
MyCmd.Parameters.Add(RecordCountParam);

// Add the query parameters
MyCmd.Parameters.AddWithValue("@MyNewValue", MyNewValue);
MyCmd.Parameters.AddWithValue("@MyKey", MyKey);

// Run the query
MyCmd.ExecuteNonQuery();

// Check the number of records affected
if (Int32.TryParse(RecordCountParam.Value.ToString(), out RecordCount)
{
	// Do Stuff Here
}

December 4, 2008

Recommendations wanted: solar charger

Filed under: Gadgets, iPod — Tags: , , — Carl @ 9:42 am

I’ve been looking a bit at solar chargers as a gift recommendation for Christmas.  I have yet to find the ideal one, so I thought I’d ask for input.  Here are the specifications that I would like to see:

  • Has internal, user-replaceable battery for storing power
  • Indicator of current charge level and solar “strength” level
  • Can charge internal battery from USB or sun, I already have a combo 12VDC/120VAC to USB adapter that would be an ideal partner for this feature
  • Has place to charge 2 AA or AAA batteries (note that a clever design could make these the internal battery)
  • Has either a clip or lanyard hole to fasten to backpack
  • Reasonable size/weight, probaby in the 1/2 pound range (minus batteries being charged) and in the “deck of playing cards” size range (which implies that the panels are foldable, I think the Solio design is nice for that)
  • USB output, pretty much any gadget I want to use can charge from that
  • No non-detatchable cords

Any recommendations?  Thanks!

Blog at WordPress.com.