Jump to content


Check out our Community Blogs

Barnsite's Blog



Shuffle an Array in C#

  Posted by Barnsite, 15 January 2013 - - - - - - · 3431 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 - - - - - - · 2428 views
programming
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
string...


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

  Posted by Barnsite, 17 December 2012 - - - - - - · 2252 views
programming
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 - - - - - - · 3579 views
programming
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 - - - - - - · 1282 views
programming
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 - - - - - - · 1168 views
programming
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:

SELECT
*
FROM bags.SAC_LOG
WHERE [SCANNERID_1] = @SCAN_ID
OR [SCANNERID_2] = @SCAN_ID
OR [SCANNERID_3] = @SCAN_ID
OR [SCANNERID_4] = @SCAN_ID
OR [SCANNERID_5] = @SCAN_ID
OR [SCANNERID_6] = @SCAN_ID
OR [SCANNERID_7] =...


Browse for SQL Server 2008 R2 Installation Media

  Posted by Barnsite, 03 December 2012 - - - - - - · 1858 views
programming
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 - - - - - - · 733 views
programming
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 - - - - - - · 864 views
programming
Just been rewriting some SQL Server stored procedures for a client. There were a lot of SELECT statements like the one below:

SELECT
   *
FROM dbo.TABLE
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 - - - - - - · 1628 views
programming
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):
WO_NUMBER...






My Picture

0 user(s) viewing

0 members, 0 guests, 0 anonymous users

Categories

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