Tag Archives: programming

Assign Event to Multiple Controls, Windows forms and C#

Lets say that you want the same event to be triggered by multiple controls. You don’t want to have to rewrite the code for all the controls. Here we’re going to use four buttons with one shared event that shows … Continue reading

Posted in Programming | Tagged , , , , , | Leave a comment

Renaming Files using C#

This is an example of how to use C# to rename files. This example takes a passed path e.g. C:\Temp\ and a ‘new name’ and renames all files in the directory with the ‘new name’ plus an underscore and an … Continue reading

Posted in Programming | Tagged , , , | 2 Comments

Parametrised SQL Server Stored Proc From ASP.net / C# / OLEDB

Lets assume that we have a stored procedure that is defined in the following way, it doesn’t really matter what the actual body of the SQL is: We want to be able to call this procedure from an ASP.net page … Continue reading

Posted in Programming | Tagged , , , , , , , , , | Leave a comment

Adding Controls to Windows Form at Runtime C#

This is a basic introduction on how to add a control to a windows form using C#. In this example we will add a button to a form with an On Click event. Firstly let’s add the button with the … Continue reading

Posted in Programming | Tagged , , , , , , | Leave a comment

Populating ASP.net DropDownList from SQL Server using OLEDB and DataTable

Firstly we need to ensure that we have referenced System.Data.OleDb in order to connect to the Database. Now the database connection: NB: for connection string help / information this is a great resource http://www.connectionstrings.com/ Now we have our open database … Continue reading

Posted in Programming | Tagged , , , , , , , , | Leave a comment

Export DataGridView to CSV File with C#

Here is a bit of code that I use to export contents of DataGridViews to csv files. This is part of an application that pulls data from various spreadsheet forms so it can be imported into a database. Firstly we … Continue reading

Posted in Programming | Tagged , , , , , , | 11 Comments

Resizing Controls with Form Visual Studio C# VB.net

I can remember having to write the code to resize control in forms. These days Microsoft have made it much easier with the Anchor property. When you put a control on a form, e.g. a listbox, you’ll find that by … Continue reading

Posted in Programming | Tagged , , , , , | Leave a comment

Moving Items between two Listboxes in C#

This example shows how you can move items between two listboxes by double-clicking on the items. To start you need a form, with two listboxes (I labelled mine lstLeft and lstRight). I also added a button (btnList with the caption … Continue reading

Posted in Programming | Tagged , , , | Leave a comment

Insert or Update Record in SQL Server Depending on Whether it Already Exists.

This is a simple example on how you can use T-SQL to Update a record if it already exists, or add a new record if it doesn’t. This example uses a table STOCK_ITEMS, with two fields ITEM_ID and ITEM_VALUE. If … Continue reading

Posted in Programming | Tagged , , , , | Leave a comment

Reverse a string in C#

Lots of people seem to want to do this… one neat way is to utilise Array.Reverse Pass the string to a char array, use Array.Reverse then pass the char array back as a string.

Posted in Programming | Tagged , , , , | Leave a comment