Jump to content

Check out our Community Blogs

Barnsite's Blog

Shuffle an Array in C#

  Posted by Barnsite, 15 January 2013 - - - - - - · 3610 views

As part of a basic guessing game I wanted to be able to shuffle an array of n chars into a random order.
The method I decided to use was the following.
Create a loop to iterate n times (where n is the number of elements in the array).  Randomly select one array element and add this to a new array.  Replace the removed item with the last item in...

Loading Data into a DataReader and Looping Through Records OLEDB / C#

  Posted by Barnsite, 24 December 2012 - - - - - - · 2502 views
Just a quick example of loading data into a data reader using C#.  My data source is MS SQL Server in this case, although you would just need the correct OLEDB connection string to use any other data source.

//database connection string & SQL Statement to return SERVICE_LEVEL_ID and DEFINITION from a table called property.SERVICE_LEVEL

Changing Default Parameter Value SSRS (SQL Server Reporting Services) 2008

  Posted by Barnsite, 17 December 2012 - - - - - - · 2330 views
If you’re here you have probably found that if you’ve deployed a report to your server updating the default parameter values and redeploying has no effect on the server report.
E.g. I had a report with an integer parameter with a default of 25 that had been deployed to the server.  On my development machine I updated the default value and...

Image Slideshow on Windows Form C# with Timer Control

  Posted by Barnsite, 07 December 2012 - - - - - - · 3680 views
Quick example of how to display an image control that loops through a folder of images.
Firstly drop a timer control onto your form (name: tmrNextImage), set the Interval to 1000 milliseconds (1 second) and set enabled to true.
Next drop a PictureBox control onto your form (name: imgPicture) and set SizeMode to Zoom (this will force your image to fit the...

Find all Subdirectories from a given path using C# – With Error Handler

  Posted by Barnsite, 07 December 2012 - - - - - - · 1396 views
In my earlier post () I showed how you can iterate through folders and add the folder names to a list (lstDirs).  The problem with this code was that if you encountered a folder you didn’t have access to it all fell over.  Below I’ve added a function to test the folder access (canReadDir()), if the folder is inaccessible the path is added to...

Search for Value in Multiple Columns SQL Server T-SQL

  Posted by Barnsite, 04 December 2012 - - - - - - · 1231 views
Having to write some SQL SELECT’s on some un-normalized tables left me thinking there has to be a tidier way. I started with:


Browse for SQL Server 2008 R2 Installation Media

  Posted by Barnsite, 03 December 2012 - - - - - - · 1935 views
When running the SQL Server Installation Centre I was receiving the above error.  This seems to be caused by the software being installed to a temp folder which is subsequently deleted post install.
Mine had been installed from a folder on the network.  Even pointing to this folder when prompted didn’t resolve the problem.
Solution that worked for...

SQL Server 2008 R2 Maintenance Cleanup Task Not Deleting bak Files

  Posted by Barnsite, 30 November 2012 - - - - - - · 851 views
I noticed that my old backup files were not being deleted despite my Cleanup Task being set to delete all bak files more than a day old.  Having checked, and double checked the path, file age, etc. I decided it was time to try a couple of random things.
Firstly I added a  to the file path, this seemed to make no difference.  So I then decided to remove the...

Multiple OR’s in T-SQL WHERE Condition SQL Server

  Posted by Barnsite, 30 November 2012 - - - - - - · 964 views
Just been rewriting some SQL Server stored procedures for a client. There were a lot of SELECT statements like the one below:

WHERE (field1 = 'SBO' OR field1 = 'RBO' OR field1 = 'PYO' OR field1 = 'TCO'
   OR field1 = 'BRS' OR field1 = 'BMS') AND field2 = 'COMPLETED'...

Null Dates in SQL Stored Procedure called from C# – Conversion Error DateTime2 DateTime

  Posted by Barnsite, 29 November 2012 - - - - - - · 1752 views
One issue with calling stored procedures from C# is with null date parameters.  If you try to pass an unassigned DateTime type to the parameter you will receive an error regarding conversion of DateTime2 to DateTime data type.
One way around this is to use the Nullable DateTime in C#
Lets assume we have the following table (dbo.Fault):

My Picture

0 user(s) viewing

0 members, 0 guests, 0 anonymous users


Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download