Archive for May, 2010

Sending Mail in C# using .Net Mail

Following self explanatory code snippets will demonstrate how to use .Net Mail to send Mail in C#. First of all, add “Using Directive” to .Net Mail and .Net Mime. The later one is for Mail attachment.

using System.Net.Mail;
using System.Net.Mime;

Continue reading

BackgroundWorker example in C# Windows Application

C# Component BackgroundWorker is used to accomplish time consuming task like mailing, taking Database Backup in a separate thread. First of all, you have to create an instance of BackgroundWorker to use it. Simply, drag and drop BackgroundWorker from ToolBox on your Form to have an instance or you may have your instance programmatically in the following way.

BackgroundWorker backgroundWorkerBackup = new BackgroundWorker();

Continue reading

MySQL Stored Function that returns Table

Don’t be misguided by the posting title. It’s not possible to write Table-Valued Stored Function in MySQL Server. MySQL Stored Function returns single values only. However, if the situation demands a Function to return a set of Data, you have only two choices.
Continue reading

Transaction with Stored Procedure in MySQL Server

Stored Procedure in MySQL Server is not atomic by default. To ensure atomicity, you need to write all your SQL Statements within START TRANSACTION .. COMMIIT Block. Moreover, you need to declare EXIT HANDLER for SQLEXCEPTION and SQLWARNINGS to ROLLBACK all of the SQL Statements in START TRANSACTION .. COMMIIT Block.


Continue reading

How to Import Data from or Export Data to CSV or Text File in DataGridView using C#

Let’s start with how to import data from CSV or Text File in DataGridView. So, first of all, you need to read the targeted File to import its content. Here, I used StreamReader to read file. It’s quite simple to read file using StreamReader.
Continue reading

Cursor with Stored Procedure in MySQL Server

Let’s start with Cursor directly. If you are not familiar with MySQL Stored Procedure, have a look at this posting first. Cursor is used to navigate thorough Result Set returned by a Query.

First of all, Cursor has to be declared. Cursor declaration is very simple.

DECLARE cursor_name CURSOR FOR select_statement;

Now, you need to use OPEN Command to start using this Cursor.

OPEN cursor_name;
Continue reading

Stored Procedure in MySQL Server

Stored Procedure is a collection of SQL commands and this is not executed until or unless called but compiled at the time of creation. Thus, this helps to reduce execution time and increases Data Integrity as well. In MySQL Server, Stored Procedure accepts three types of argument.

1) IN
2) OUT
Continue reading