Posts

Showing posts from January, 2012

Insert, Update and Delete Data using DataGridView and save changes to database:

GridView is a control that provides you a very easy way to insert update and delete data and save modifications to database. You only have to make changes in GridView and click the button changes will be saved to database. Here is an example which shows how to save changes to database. ·          Start a new WindowsFormApplication. ·          Make a connection with database. ·          Add a button on the form for inserting and updating data. ·          Add another button on the form which will delete record. ·          Add a DataGridView on the form located in Data section of toolbox. ·          Select the DataGridView and go to properties. ·          Change the name property of DataGridView to MyDataGridView. Now here is the code for this example; using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.Data.SqlClient; namespace Dat

Using Progress Bar In C#

Image
Using Progress Bar in C#: Progress Bar is very commonly used control in many applications to display the progress of task being performed. Progress Bar is displayed when copying files, deleting files or installing some software. How to use Progress Bar: ·          Start New Windows Form Application. ·          Go to Toolbox. ·          Select Progress Bar and Drag it to your Form. To make Progress Bar working you need to know some properties of Progress Bar Progress Bar.Maximum: Defines how long it should run Progress Bar.Step: Defines how much it should increase current position of Progress Bar. Progress Bar.Style: How should it look like? There is also a very basic method which is used to run Progress Bar properly. Progress Bar.PerformStep() Let’s see an example. In this example we will copy files and folders from one location to another and show the progress bar while copying. using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using

Copying Files In C#

Copying Files in C#: There are many ways in c# to copy files and many classes available which allow different operations on Files. The commonly used class in c# to copy files is FileInfo. FileInfo is defined in System.IO . The method used to copy files in FileInfo class is CopyTo() . Now here is an example how to copy a file. class Program     {         static void Main( string [] args)         {             FileInfo fi = new FileInfo ( @"F:\Posts\Email Links.txt" );             fi.CopyTo( @"F:\Posts\new.txt" );                    }     } Copying Folders and Files: In above example we have created an object of FileInfo class and specified the file path we want to copy.Then we called CopyTo() method and specified the file path and name where we want to copy the file.In this example we have copied only one file if we want to copy all files in a Directory logic will be bit different.This example will show how to copy all files and folders present in a Directo