My thoughts regarding ASP.NET, C#, programming practices, and more...
reading
You Should Read archives
blogs I read
|
Wednesday, August 24, 2005Get Index of Item Being Bound to DataGrid
Problem
If I am binding a DataTable to a DataGrid, how do I get the index of the DataRow that is being bound so I can use it at runtime? Solution After some initial searching using Google I thought my solution would be to use the DataGridItem.ItemIndex property. While testing I determined that the DataGridItem.ItemIndex property provides you with the index of the item in relation to the DataGrid. In my case I am using this in a pageable DataGrid. No matter which page the user chooses the record being displayed at the top of the grid always has an index equal to 0. Unfortunately this might by on page 2 where the actual DataRow index of the item is something like 15 (15 items being displayed per page). Following more digging I found that the DataGridItem.DataSetIndex property contained the "The index number of the DataGridItem object from the bound data source.". Bingo! Wednesday, August 17, 2005Visual Studio Database Projects and Command Files
Database Projects in Visual Studio .NET (Good primer by Scott Mitchell)
Visual Studio.NET Database Projects (Excellent in-depth article by Jeffrey McManus and Jackie Goldstein) After reading the above articles you will learn about creating command (.cmd) files. These files will make your life easier by allowing you to execute one file to complete all of your SQL Server database updates. Unfortunately, if you are using Visual Studio 2005, you will also learn that the "Create Command File" function is now missing from the IDE. You can learn more about this and see an example .cmd file by visiting this blog posting by Kirk Marple. Using example .cmd file content from both Jefferey McManus and Kirk Marple, as well as well as the osql Utility syntax page, I was able to create my own .cmd file. Pay careful attention to the line that calls osql. Example: osql -S %1 -d %2 -U myUsername -P myPassword -b -i "BS_Application_Part1.sql" Notice that I replace -E (trusted connection) option with -U (username) and -P (password). Redirect Browser to HTTPS
By adding the following code to your Global.asax, you can determine if a user's browser is accessing your site using SSL and if not, automatically redirect their browser to the same URL with an HTTPS prefix.
Tuesday, August 09, 2005Helpful: C# to HTML; 101 VS 2005 Code Samples
C# Code Format
I was trying to find a tool to format C# source code into HTML to use in content pages. I came up with Jean-Claude Manoli's C# Code Format. The only drawback is that it needs to be updated to use the new VS 2005 color formatting. 101 Samples for Visual Studio 2005 "101 Samples, in both Visual Basic and C#, featuring many of the new features available with Visual Studio 2005 and the .NET Framework 2.0" The examples include: - Base Class Libraries - Data Access - Web Development - Windows Forms You can see a summary list of the examples and download them from Microsoft's website. Tuesday, August 02, 2005Copying Database from Server to Server
Description:
Content copyright ©2003-2006 Tod Birdsall
I have two SQL servers. A production (sql-prod1) and a staging server (sql-stage1). The staging servers job is to be a mirror image of the production server so that when I push my latest bug fixes, I can make sure that any problems are resolved in staging, before pushing to production. As often occurs, the staging server was getting more and more cluttered with test data, and was looking less and less like the production server. I requested that the DBA replace all of the databases in staging with their corresponding databases in production. Unfortunately for me, the DBA has his own problems. So, I found a fellow programmer who could give a DBA a run for his money and asked him to walk me through the process and he was patient enough to allow me to jot the steps down so I would not forget them in the future. For your benefit as well as my own, I have pasted these steps below. Enjoy. How-To: Backup Database 1. Right click database, choose "All Tasks" -> "Backup Database" 2. Make sure "Database - Complete" is selected (should be the default) 3. Verify that the "Destination" area includes the file path where you wish to store the backup. 5. Choose "Overwrite Existing Media" if the above filename already exists. 6. Leave everything else default. How-To: Restore Database 1. Select Database, choose "AllTasks" -> "Restore Database" 2. Choose "From Device" 3. Click "Select Devices" 4. Click "Add" 5. Choose File from backup processe above, click "OK". Click" OK" again to go back to main Restore Database form. 6. Click "Options" tab. 7. Check "Force restore over existing" 8. Verify that "Move to physical file name" are pointed to the correct paths (normally the default is correct) 9. Click "OK". |