Archive for the 'Uncategorized' Category

Executing a SQL Server stored procedure in C#

Are you kidding me? I’m a major amatuer at anything .NET, and after some Googling and about 15 minutes of coding, this works. How ridiculously easy.

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Text;
  4. using System.Data;
  5. using System.Data.SqlClient;
  6.  
  7. namespace ExecuteStoredProcedure
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. SqlConnection conn;
  14. try
  15. {
  16. conn = new SqlConnection("server=server;database=db;Trusted_Connection=yes");
  17. conn.Open();
  18. Console.WriteLine("Connection successful…");
  19. }
  20. catch (Exception ex)
  21. {
  22. Console.WriteLine(ex.Message);
  23. return;
  24. }
  25.  
  26. SqlCommand db_cmd = new SqlCommand("dbo.usp_c_sharp_test",conn);
  27. db_cmd.CommandType = CommandType.StoredProcedure;
  28.  
  29. SqlDataReader data_reader;
  30. data_reader = db_cmd.ExecuteReader();
  31. data_reader.Close();
  32. conn.Close();
  33. }
  34. }
  35. }

I ate it

I just turned the corner from the kitchen to the dining room, and met up with our three year old son, and he hit me with this:

Son:
There was a booger in my nose.
Me:
And…what did you do with it?
Son:
I ate it.

Oh, the brutal honesty that is childhood.

Converation Viewer now an official WordPress plugin

I finally got around to getting Conversation Viewer into the WordPress plugins SVN repository. Been meaning to do that for a while. Version 1.0.0 can be had from the trunk at:

http://svn.wp-plugins.org/conversation-viewer/trunk/

The writeup and instructions/examples of usage can be found here .

Retro - It’s all about the donuts

Kids are amazing little buggers, especially when they are your amazing little buggers. One of the most amazing things about having kids is that you can actually learn from them. Yeah, imagine that. Something I have learned from our boys is that it really is the little things in life that make it all worth while. Take for example, donuts. Last summer, we flew from our humble little home in northwest Arkansas to Seattle to visit the wife’s sister and boyfriend, and we took the boys. We stayed in this crappy little motel downtown right near the Space Needle (location, location, location). It was cheap, and we figured “Hey, all we’re going to do is sleep there, right. How bad can it be?” When we got there, the little one was asleep in the car so the wife and the big one went in to “check it out”. Upon return, the wife said that “…it’s not that bad”. I later realized that it was one room barely large enough to hold the king size bed all four of us were to sleep in for a week. Oh, and the bathroom only had a shower, no tub to give the boys a bath in (although they found showers to be quite a novelty that week). Now, if I was going to go back to Seattle, I probably would choose another place to stay. Granted, it wasn’t that bad; it was clean, the staff was friendly and helpful, and did I mention the donuts? No? Well, if you asked our boys if they wanted to go to Seattle tomorrow, they would INSIST on staying in that hotel. Why, you ask? Well, the donuts, of course. Every morning the staff would put out this huge spread of donuts, pastries, muffins, and bagels, and once the boys found out about this, they would shoot out of bed every, yes every morning and want to go get donuts. At 6 AM. So we would go to the lobby, my wife or myself barely awake, the boys still in their pajamas, and get donuts. Lots of donuts. Way too many donuts. About an hour later, our room looked like a donut factory where some sort of explosion had taken place. Sprinkles here, frosting there, donut detritus everywhere (hey, that rhymed). Yeah, if we go back to Seattle with the boys, I think we all know where we will be staying.

Concatenation and logic in SQL calls

I’ve been doing alot of database design lately, although nothing too fancy, just some personal Access databases. However, I have run across some cool stuff that really got me excited (as pathetic as that may seem): concatenating fields and using logic in SQL calls. The only thing that aggravates me is that I’ve went this long without knowing of these little jewels. The concatenation is pretty straightforward; take field A and concatenate field B to it, then alias it as field C, like so:

SELECT tableA.fieldA & " " & tableB.fieldB AS fieldC

which gives you the data in fieldA concatenated to fieldB, separated by a space, as field C.

The logic is even better. I was importing the data from Access to Excel, so I could insert the Excel sheets into a map, all prettied up with lots of formatting. It worked great, except one field in my database contains null values, and when I imported that field from Access, Excel put zeros in place of the null values. This was unacceptable. So I figured that with the IIf function in my SQL call, I could get only the records from the field that were not null. Problem solved. In the end, the call looked something like this:

SELECT tblWell.Well_Name & ' ' & tblWell.Well_No AS ShortWellName, tblWell.SpudDate, tblWell.Status, tblCompletion.Frac, tblGeology.RHOB_Pay_T, tblGeology.Shale_Thick, tblProduction.Online_Date, IIf(tblProduction.Rate<>‘ ‘,tblProduction.Rate & ” on ” & (Format(tblProduction.Rate_Date,”m/d/yyyy”))) AS CurrProd
FROM (((tblWell LEFT JOIN tblCompletion ON tblWell.ID = tblCompletion.ID) LEFT JOIN tblGeology ON tblWell.ID = tblGeology.ID) INNER JOIN tblProduction ON tblWell.ID = tblProduction.ID) INNER JOIN tblFieldNames ON tblWell.FieldNo = tblFieldNames.ID
WHERE (((twlWell.Status)<>‘Proposed’)) AND (((tblFieldNames.FieldName)=’Whatever Field’))
ORDER BY SpudDate ASC;

Whew.

Conditional SQL

Conditional SQL?? How have I went this long with out knowing about this? The power of SQL amazes me every day.

Retro - Jack, there’s no speed limit in Montana!

The Wife and I were in Mexico on our honeymoon last year. One evening, we were at the resort bar, sitting outside on the patio, and this older (60’s) American (and judging from what they talked about the entire time, obviously very wealthy) husband and wife were sitting behind me. Part of their conversation went like so:

Jack’s Wife:
What ever happened to old what’s his name?
Jack:
Who?
Jack’s Wife:
*Tries to describe "what’s his name" to Jack.*
Jack:
Oh, he moved to Montana.
Jack’s Wife:
MONTANA? But he’s a hairstylist, people in Montana don’t get haircuts, they cut their hair with hacksaws. And they kill their food with their bare hands.
Jack:
*Laughs*
Jack’s Wife:
Jack, there’s no speed limit in Montana.

Evidently Montana is inhabited, at least in the mind of Jack’s wife, only by hacksaw wielding animal killers that haul ass in their cars with no regard for how fast they are going. Well Jack’s wife, I have to say, I’ve spent a few summers in Montana myself, and I’d have to admit that you really aren’t that far from the truth.

Google Maps

Goodbye Mapquest, hello Google Maps.

I’m in love

Her name is mod_rewrite. Ever heard of her? She’s an Apache module, and man is she gorgeous. We first met last year. At first she really confused me and sent me mixed signals. On one minute, off the next; you know, like code or something. Always leaving me wondering “Is this really going to work?” Sometimes, if I do just the wrong thing, everything comes crashing down. It doesn’t take much. But once I figured her out, it’s amazing what I’ve gotten her to do for me. Things like redirects, URL rewrites - I’m getting chills just thinking about it. Oh, but don’t anyone tell my wife about this, she’ll kick mod_rewrite’s ass.

Panoramas

Three of these are from recent photos, one is from older ones.

wed_balconyThis series of photos was taken in April of 2002 from the balcony of the beach house where my sister got married on Pensacola Beach, FL. The view is looking west out onto the Sound.

illinois_mosaic1Taken April 23, 2004. This series was taken after several days of heavy rain which caused the Illinois River to flood out of its banks. The location is in northwestern Washington County, along CR66.

illinois_mosaic2Taken April 23, 2004. Also of the Illinois River flooding, this is along Washington CR62, looking south (main river channel is on the right side of photo). All of the flooded area here is pasture. It shoud be noted here that these pix were taken after the river had went down some earlier in the day.

Baseflow x100Taken April 24, 2004. This is a mosaic of about 15 photos of the spring just off the south side of our property. Under baseflow conditions, this spring is just a trickle coming out of the Pitkin limestone. After the storm, however, it sounded like there were Class 4 rapids back there, so I went to check it out, only to find this, and it flowed like this for about 4 days after the rains. Note that my site header is a clip from this mosaic, I just love the way you feel like you are right at the water level, seeing it come pouring out of the spring.