Quarksoft Blog

This is where we post useful information for everyone. Lots of it is technical, but some can be used by anyone.

Archive for the ‘Programming’ Category

Custom Parameters with ObjectDataSource and SqlDataSource

Found a decent article about custom parameters for data sources in ASP.NET.  It was written by Eilon Lipton who has been on the ASP.NET team for quite a while at Microsoft.  The article discuss how to insert your own custom parameters and has easy examples and a good explanation.

GridView with DropDownList – Server tag is not well formed.

Ran across an issue today when trying to get my DropDownList embedded within a GridView.   Here is an extract of the code (the error is in the red text):

<ItemTemplate>
  <asp:DropDownList
        ID="ddlMaker"
        runat="server"
        DataSourceID="odsMakers"
        DataTextField="makerName"
        SelectedValue="<%#Bind("MakerID") %>"
        DataValueField="makerID">
  </asp:DropDownList>
</ItemTemplate>

When I compiled I received an error “The server tag is not well formed.”

After a bit of trial and error I realized it was because there were quotes nested within quotes. To make this work all that had to be done was to change the outside double quotes on the SelectedValue parameter to be single quotes as shown below.

<ItemTemplate>
  <asp:DropDownList
        ID="ddlMaker"
        runat="server"
        DataSourceID="odsMakers"
        DataTextField="makerName"
        SelectedValue='<%#Bind("MakerID") %>'
        DataValueField="makerID">
  </asp:DropDownList>
</ItemTemplate>

Hope I saved someone a bunch of wasted time.

ASP.NET AJAX Control Toolkit Samples

Most of you probably have already experimented with the Control Toolkit, but just in case you never ran across it, take a look at these Toolkit samples

If you have any questions about them, drop me a comment here.

Useful way to reformat an ASP.NET File Upload control

The guys over at QuirksMode.org have come up with an interesting way to get around the default styling of a File Upload control See the details here:

http://www.quirksmode.org/dom/inputfile.html

So what do you do with all those IIS log files?

You are responsible for one or more Windows web servers and you have all these IIS log files that you want to make some sense out of.   If you have some basic SQL skills Microsoft is making available a utility called LogParser which does a great job getting in there and allowing you to query the files directly using some basic SQL syntax.   The feature I like the best is the ability to convert the data into a SQL table for manipulation via T-SQL.

Here is a sample of what I did (this would all go on a single line)

c:\”program files”\”log parser 2.2″\LogParser -iCheckPoint:myCheckPoint.lpc -o:SQL -server:localhost -database:IISLogs -createtable:ON “SELECT * FROM ex0810*.log TO IISLogs”

This short command line will read in all log files that start with ex0810 and import them into a table called IISLogs.  It will also create a checkpoint file so that if you run the command again it will not import records that have already been imported.

How cool is that?

Once all the importing is done you can leverage the SQL tables using whatever methods you need to.

If you need any help with stuff, send us a note at support at quarksoft.com.

Outlook 2007 Preview Pane made useful…

I finally had upgraded to Outlook 2007 about a month ago and one of the features I found myself using a lot was the Preview feature for attachments. It was great for the PDF and the typical office documents, but there were no preview handlers for files such as WAV. I have a VOIP line that emails me the voice mail messages that have been left so having a WAV previewer would be really useful for me.

During my search for such a feature I ran across a great utility from Gil Azar (and in his post gives credit to lots of others for their help). You can download the ultimate Outlook 2007 preview handler from his site.

If you are interested in some of the technical details Gil discusses them on his page and provides some really great links.

I’ve included parts of Gil’s original post just in case his site disappears one day.

A self-extracting installer, which silently installs Stephen Toub’s MSDN Magazine Managed Preview Handler Framework and Gil’s small addition, can be downloaded here

ASP.NET Session State in SQL Server

There are lots of places to get information about putting the Session State into a SQL Server database instead of in-memory. The information I have found most useful is the utility aspnet_regsql.exe. It performs a bunch of different tasks for ASP.NET and interaction with SQL Server and the membership interfaces.

For example if you want to get session persisted across SQL Server reboots you can issue this command:

aspnet_regsql.exe -ssadd -sstype p -E -S <servername>

The sstype p is the option that allows for the state to be persisted. You can execute aspnet_regsql.exe -?

Resetting the IDENTITY counter in SQL Server T-SQL

You’ve been there before.  You are busily testing your import routines and running up the Identity column in your main import table.  Before you know it the value is in the multi-millions and you just want to reset it back to 1. 

The way to accomplish this is to use the DBCC CHECKIDENT command.

For example:

DBCC CHECKIDENT (SalesForce, reseed, 0)

This assumes your table is called SalesForce and you want to start the numbering at 1.  If you wanted to start the number at 2000 you can substitute 0 with 1999.  There has been some discussion that has said if the table never had records added to it the reseed value itself will be used instead of the reseed + 1 value.  You should not need to use this statement for a “new” table.

Credit for this post is given to Pinal Dave over at http://sqlauthority.com/.  The specific post this I am referring to is the one at this page.

Helping block spam with T-SQL

Found a great article on blocking spam using T-SQL code.  It is especially useful for blog posts and other community related sites that accept user input.  Could even be used on form comments to help block all those guys that submit endless forms on your sites.

 

Disabling buttons on click for ASP.NET forms

Found some great tips in the simple-talk.com blog about disabling buttons on asp.net forms.

If you ever created a form and had your users click on the submit button multiple times this is the code you have been looking for.  Be sure to check out Robyn Page’s comments for a method to block the whole form during the form submit as well.

Complete details can be found here.

Creating Dates in SQL Server... FAST!