I was just going over a few notes, when I had a quick little project in which I needed a SQLDataSource control, and I thought I’d present what I found here.

The first thing I found, was how to find out when the DataSource control, using it’s Select method, actually returned any records. Sometimes, if it returns no records, you might need to do something else, for instance.
To do this, use the Selected event of the SQLDataSource. In that event, check for e.AffectedRows. In Visual Studio, go to the properties of the SQLDataSource. Then click on the lightning icon up at the top of the Properties window (when you hover over it, you will see ‘Events’). Double-Click on the ‘Selected’ event, to give you an event handler in your code. Inside that handler, type in something like this:

If e.AffectedRows < 1 Then
     ' do something here
End If
if ((e.AffectedRows < 1)) {
    //  do something here

Another thing that is not exactly straight forward is one area of parameters. You might have noticed that, when using Visual Studio to create parameters for your DataSource control, it has a finite number of sources for these parameters (cookie, profile, form, querystring, session, control).

But what if your parameter’s source was a variable, or a the user’s authenticated name? Where would you put it then?

The answer is by using the ‘Selecting’ event (create the handler like it was outlined above). Inside that event handler, put something like:

e.Command.Parameters("@UserID").Value = User.Identity.Name
e.Command.Parameters["@UserID"].Value = User.Identity.Name;

That’s it for now – – let’s call this Part 1. If I come up with any more, I’ll create Part II :)