Thursday, July 31, 2008

TSQL Drop Table If Exists

Using SQL Server I have needed to drop functions and stored procedures before creating them in a script. Today I had to drop a table. After searching around a bit I found that I could test if the drop was necessary using much the same syntax as the others.

IF EXISTS (SELECT * FROM sys.objects WHERE object_id = OBJECT_ID(N'[dbo].[TableName]') AND type in (N'U'))
DROP TABLE [dbo].[TableName]

The type of the object is U for USER_TABLE.

Thursday, June 5, 2008

Assigning Variables Values in SQL Server TSQL

This trips me up every now and again as I switch between coding SQL and coding other things.

The keyword SET is required before a variable assignment. I see to recall that BASIC use to have this requirement as well.

DECLARE @myInteger INT

SET @myInteger = 7

Friday, April 18, 2008

Statements can only be used fo calls, assignments...

This C# error probably means that you have tried to call a function without parethesis after it. For example, typing:
Instead of:

Thursday, February 7, 2008

Formating Dates in the GridView

I set up a bound GridView. I had several bound fields. A couple of the field were dates. The data source was a date time field. I did not want the time portion, so I used
DataFormatString="{0:MM/dd/yyyy}" on the BoundFields. On my development box it stripped off the time. When I deployed to the server it was still showing the times.

The solution was to add HtmlEncode="False" to the bound fields.

Thursday, January 31, 2008

Using CustomValidator to Validate empty (blank) Textbox

I started my page by using a RequiredFieldValidator, but later found that I needed to validate on more complex criteria as well as if the field is empty. When I added the CustomValidator I found that my code was not firing if the TextBox was empty. After researching this I found that there is a property of the CustomValidator called ValidateEmptyText. The default is false. Once I set this to true it worked and I was able to remove the RequiredFieldValidator.

I'm not sure which version of .Net this property exists in. My page was running on .Net 2.0.

Friday, January 11, 2008

Checking the Value of an HTML Checkbox in Classic ASP with VBScript

I spent several hours being rolled around by this. It appears as though that when you do request.Form("Control") the parameter takes the value of the name property and not the value of the ID property. So I got myself confused since I was doing some stuff client side in javascript as well as in VBScript server side. I generally use getElementById in javascript.

I was only setting the ID property and trying to use the request object to find the id.