Monday, September 10, 2007

ASP.NET and MS SQL Server 2005 - Bit / Boolean Type

Ok, I'm not a hardcore programmer, so today I found something that was quite wierd to me at least.

Now I have MS SQL Server 2005 as my backend database. I created a simple type with a couple fields, one being of type "bit", which can hold the values of 1, 0, or null. Since there isn't any boolean type, then this is what should be used for true and false data.

Now, I am programming in ASP.NET which communicates with the database. I was trying to do a simple INSERT command into this table and for awhile I couldn't figure out why it wasn't writing into it.

For example my SQL statement in ASP.NET could be like this:
Ex1. INSERT table1 (x1, x2, y1, y2) VALUES ('hello', 'there', True, False);

Or say I have a couple radio buttons R1 and R2 somewhere:
Ex2. INSERT table1 (x1, x2, y1, y2) VALUES ('good', 'bye', R1.Checked, R2.Checked);

In SQL Server: x1 and x2 are nchar(10), y1 and y2 are bit

Both statements did not work. If I actual values like 1 or 0, those will work.
Ex3. INSERT table1 (x1, x2, y1, y2) VALUES ('good', 'bye', 1, 0);

The only way to get Ex1 and Ex2 to work is to put bound the True or False by single quotes like a string.
Ex4. INSERT table1 (x1, x2, y1, y2) VALUES ('hello', 'there', 'True', 'False');

To me that is very confusing. But that's how SQL Server takes it.

Dreamweaver - Centering Layouts

This is quite easy to do, but was hard to find out how. If you want your website to always be centered no matter what monitored is being used. Do the following:

1. Make a new table.
[Rows = 1, Columns = 1, Width = 100%, Cell Padding = 0, Cell Spacing = 0, Border = 0]

2. Check inside the table and set: Horizontal align to "center", Verticle align to "middle"

3. Now make another table of any size inside the one you just made and it will always be centered.

MS SQL - Reseting IDENTITY value

If you want to reset your identity field to a certain number, use the following statement:

DBCC CHECKIDENT ('tablename', RESEED, new identity value)