Thursday, August 19, 2010

IE8 And Visual Studio Debugging Fail

I told Jason I was going to make this into a short story, but since it's 4:25 I decided not to.

The long and short of it is:

IE8 and Visual Studio debugger do not work well together. Well at least VS2005 and IE8 do not work well together unless you only have one IE8 Browser open (the one you are debugging in - this happens in firefox as well).

If you have multiple IE8 browsers open, your debugger will not stop on your breakpoints when you are running your code. (try it, its fun! Maddening at first when you cant get any of your debugging techniques to work, but fun after you pull out your hair)

I looked up this issue and found this information here

Enjoy! and um... dont lose your hair over this!

Friday, July 30, 2010

SQL Server Guidelines

I saw this out on the SQL Authority blog and thought that I'd pass the link around, seeing as the author doesn't want it printed or even downloaded. It's certainly not a bad thing to have a SQL reference, or change it up, even your style is already ingrained into your brain. Check out this link below for a decent SQL notation reference. I find that I already follow alot of these standards, except for the lookup table notation. I always used "LKP_Tablename" notation when creating those. I think I'm going to change my style.

Let me know what yinz think.


http://www.pinaldave.com/sql-download/SQLServerGuideLines.pdf

Friday, July 23, 2010

list all tables in a database

So I'm documenting a database with 21 tables in it. I wanted A quick way to get them listed. Voila:

SELECT *
FROM information_schema.Tables where table_type = 'base table'



note that I added the WHERE clause. Without it, I also got all of the views.

Friday, July 2, 2010

time tracking tool

I was reading about Toggl, which seems pretty cool, and free.

http://www.toggl.com/public/tour

Don't know how people are tracking their time these days. I liked Allnetic's tracker until they decided to charge for it :P

Since toggl is web based you don't need to be tied to a machine to track your time, although I don't know if the desktop tool syncs up - I would assume so though.

Monday, April 26, 2010

formatting data in a gridview that's auto generating columns

What a long title! Anyway formatting the cell's onrowdatabound is quite well documented but all of the discussion tends to assume that you'll have specified columns, so you'll have BoundColumns and TemplateItems to work with. But I wanted to use short dates in a gridview where I was letting the gridview auto generate the columns (the default unless you set it to false in the gridview properties).

I only found this little reference to it - you need to scroll down to find the relevant code sample underneath Community Content (http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogeneratecolumns%28VS.80%29.aspx). I used a free code converter change it to C# but that code still needed work. The original converted code with original comments, and then mine added in below. This code is easily customized for a wide range of formatting output when your gridview is automatically generating columns.


protected void Gridview1_RowDataBound(object sender, GridViewRowEventArgs e)
{
//use syntax to hide baddates
//maybe also do short date strings?

//http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.autogeneratecolumns%28VS.80%29.aspx
// Routine to display an unknown DateTime column
// as a short date at runtime
// By Ken Cox [Microsoft MVP]
// July 28/06
//
// Make sure this is a datarow being bound
if (e.Row.RowType == DataControlRowType.DataRow)
{
// Create variables to hold values
DataRowView dtview = default(System.Data.DataRowView);
int intCounter = 0;
// Get the contents of the current row
// as a DataRowView
dtview = (DataRowView)e.Row.DataItem;
// Loop through the individual values in the
// DataRowView's ItemArray
for (intCounter = 0; intCounter <= dtview.Row.ItemArray.Length - 1; intCounter++)
{
// Check if the current value (item - Layla) is
// a System.DateTime type
if (dtview.Row[intCounter].GetType() == typeof(DateTime))
{
// If it is a DateTime, cast it as such
// into the variable

//Layla: cast item to DateTime
DateTime myNewDate = Convert.ToDateTime(dtview.Row[intCounter]);
//now test if that date is missing date, then hide it if so
if (myNewDate == myConstants.NOTCOMPLETE_DATETIME)
{
e.Row.Cells[intCounter].Text = "";
}
else
{
// Set the text of the current cell
// as the short date representation
// of the datetime
e.Row.Cells[intCounter].Text = myNewDate.ToShortDateString();
}
}
}
}
}


If you compare the original code you can see some small differences. Rather than create a DateTime variable holder to place the item into, I just create the variable IF NEEDED (if the item in the row being evaluated is of type DateTime) and populate it with the item cast as a DateTime. Very small, but I prefer that because I think it's easier to read/understand.

If anyone knows of any other ways to accomplish this - namely iterating through the items in a gridview row onrowdatabound, I'd love to compare it, so tell me about it in the comments!

Tuesday, April 13, 2010

.NET Validators

I have been working a lot with .NET validators recently. I found this article that explains about them quite in depth: http://msdn.microsoft.com/en-us/library/aa479045.aspx

There are two new tricks I took out from this:
1. You can fire an individual validator from javascript using this: ValidatorValidate(document.getElementById("yourValidatorId")). I found it useful in this situation: I have a field taking a temperature value and they wanted to enter either in Fahrenheit or in Celsius. I made two text fields, one for Fahrenheit and one for Celsius, and one validator to validate the range of the Celsius field. When one value is entered or changed, javascript calculate and populate the other value. I didn't want to use one validator for each field because there was no room. So if I entered a value in Fahrenheit that was out of range the Celsius validator wouldn't fire until I submit the form. Now I can call the validator right after I convert Fahrenheit to Celsius so the Celsius field gets validated immediately.

2. You can use ValidatorHookupControl(control, val) to link controls to validators. It's helpful when you have a customvalidator. Without the hookup the validator wouldn't fire immediately. For example, you submit a form and then find that some control is not valid. You fix the problem but the error message won't disappear right away. The built-in validators such as requiredvalidator fires when the control is changed. So users will get confused by this inconsistent behavior, they might think they didn't fix the problem correctly.

Wednesday, March 31, 2010

Solution Items

I recently discovered that you can right click on the solution in Visual Studio in the solution explorer panel, you can add items that will be kept in the root directory. So in my case, I have an application which will consist of a questionnaire and a tracking application. I removed the web.config from each project and instead added one config to the solution items. My directory now has the main Root folder (let's call it ResearchStudyName) inside which is the config, and a generic error page I added called error.htm, and inside ResearchStudyName are 2 directories, Questionnaire and Tracking.

Now in order for the needed files to be there upon publish, I add them as linked files to each project by using Add > Existing Items whereupon I navigate to the files in the root dir, and drop down the Add button to change it to Add as Link.

All done!