Saturday 26 April 2014

Change column title of datagridview when connecting Sql Server in window application



                                                                                                                                           Previous...
                                                                                                                                               Next....
Here i will explain How to  Change column title of datagridview when connecting Sql Server.

Step(1): Form
Drag and down a data Gridview and a Button from tool box.
Step(2): Code
Now click on Botton (Load Button). and write this code

 private void Load_button_Click(object sender, EventArgs e)
    SqlConnection con = new SqlConnection("server = MUNESH;Database=datastore;UID=sa;Password=123;");
    SqlCommand cmd = new SqlCommand("Select Eid as 'Employee Id', Name as 'Employee name' , surname as 'Employee surname' ,Age as 'Employee surname' from data1", con);
    try
   {
        
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataTable dt = new DataTable();
        da.Fill(dt);
      BindingSource bsource = new BindingSource ();
    
    bsource .DataSource = dt;
        dataGridView1.DataSource = bsource ;
       
    }
    catch (Exception ec)
   {
        MessageBox.Show(ec.Message);
   }

Step(3): Run
Now run your application.

                                                                                                                                           Previous...
                                                                                                                                               Next....

How to Exit from this application



                                                                                                                                          Previous....
                                                                                                                                                  Next..

Here i will explain how to exit from this application.

Step(1):- Form

GO to form "Events"  there is a event "FormClosing" click on it
Step(2):- Code

Private void Form2_FormClosing(Object sender , FormClosing EventArgs e)
{
Application.Exit();
}

If you want to close your application at button click event write this code

private void btnclose_Click(object sender, EventArgs e) 
{
This.close();

If you want to that before closing a Pop Up show that you want to close this application or not then.

Private void Form2_FormClosing(Object sender , FormClosing EventArgs e)
{
DialogResult dialog = MessageBox.show("Do you want to close application", "Exit", MessageBoxButtons.YesNo);
if(dialog ==DialogResult.Yes)
{
Application.Exit();
}
elseIf(dialog ==DialogResult.No)
{
e.cancel= true;
}
}


Step(3):- Output
Now run your application and close this application as gracefully.
                                                                                                                                          Previous....
                                                                                                                                                  Next..

Friday 25 April 2014

How to use progressBar and button in window appliaction


                                                                                                                                           Previous..
                                                                                                                                                 Next..

Here i will explain how to use progress Bar in window application.

Step(1):Form
Drag and down a progress Bar and a button and a timer from tool box.
Step(2):Code
Double click on progress bar and timer and write this code.
private void btnprogress_Click(object sender, EventArgs e) 
{
    this.timer1.start();


Now double click on timer

private void timer1_Click(object sender, EventArgs e) 
{
    this.btnprogress.increment(1);


We can also control the speed of the interval by a timer property.




Step(3):Output
Run your application and click on button.
                                                                                                                                           Previous..
                                                                                                                                                 Next..

Dynamically display Current date and time in window form


                                                                                                                                          Previous..
                                                                                                                                                Next..

Here i will explain how to display current date and time by using code in window form.

Step(1):- Form
Drag and down a Leble and a timer from toolbox. when you drag and down a timer it will go down. you can change its property like interval.
Step(2):- Code

Double click on timer and write this code


Private void timer_Tick(object sender, EventArgs e)
{
DateTime datetime = DateTime.Now;
this.time_lbl.Text = datetime.ToString();
}
Private void time_lbl_Click(object sender, EventArgs e)
{

}
And you go at  " InitilizeComponent" and write below this
        timer1.start();

Step(3):- Output

Now run your application
                                                                                                                                          Previous..
                                                                                                                                                Next..

Wednesday 23 April 2014

How to link chart Graph with database in window form


                                                                                                                                       Previous
                                                                                                                                           Next

Here i will explain that how to connect Chart-Graph with database.

Step(1): Form
Drag and down a chart graph and a button from tool box.

Step(2): Coding
Now click on Button (Load Button). and write this code


private void Load_button_Click(object sender, EventArgs e)
    SqlConnection con = new SqlConnection("server = MUNESH;Database=datastore;UID=sa;Password=123;");
    SqlCommand cmd = new SqlCommand("Select * from data1", con);
DataReader mydatareader ;
 try
   {
con.Open();
myreader = cmd.ExecuteReader();
while(myreader.Read())
{
this.chart1.Series["Age"].Points.AddXY(myreader.GetString("name"),myreader.GetInt32("Age"));
}
}
Catch(Exception ex)
{
MessageBox.show(ex.message);
}
}
Step(3) : Run
Now run your application and click on button.
                                                                                                                                       Previous
                                                                                                                                           Next

Sunday 20 April 2014

How to use chart graph in window appliaction


                                                                                                                                        previous..
                                                                                                                                             Next..

Here i will explain how to use Chart Graph window application.

Step(1) : Form
Drag and down a chart graph and a button from tool box.

You can change properties  of this chart graph. Main property of this chart graph is "collection"
From this we set Graph as a X-axes and Y-axes. Here i am meking graph b/w Age and score.You can change color and background image.
Step(2) : Code
Click on button and write this code.

Private void Chart_btn_Click(object sender, Event args)
{
this.chart1.Series["Age"].Points.AddXY("max",33);
this.chart1.Series["Score"].Points.AddXY("max",93);

this.chart1.Series["Age"].Points.AddXY("carl",20);
this.chart1.Series["Score"].Points.AddXY("carl",70);

this.chart1.Series["Age"].Points.AddXY("mark",50);
this.chart1.Series["Score"].Points.AddXY("mark",56);

this.chart1.Series["Age"].Points.AddXY("Alli",40);
this.chart1.Series["Score"].Points.AddXY("Alli",30);

}
Step(3) : Run
Now run your application and click on button.
                                                                                                                                        previous..
                                                                                                                                             Next..

Show database value in DataGridView in window application


                                                                                                                                             Previous..
                                                                                                                                                Next..

Here i will explain that how to show Database value in DataGrid View.

Step(1): Form
Drag and down a data Gridview and a Button from tool box.
Step(2): Code
Now click on Botton (Load Button). and write this code

 private void Load_button_Click(object sender, EventArgs e)
    SqlConnection con = new SqlConnection("server = MUNESH;Database=datastore;UID=sa;Password=123;");
    SqlCommand cmd = new SqlCommand("Select * from data1", con);
    try
   {
        
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataTable dt = new DataTable();
        da.Fill(dt);
      BindingSource bsource = new BindingSource ();
   
    bsource .DataSource = dt;
        dataGridView1.DataSource = bsource ;
       
    }
    catch (Exception ec)
   {
        MessageBox.Show(ec.Message);
   }

If you Don't want to load data in datagrid view at button click then you can make function for filling this datagridview.

public void displayDataGridView()
{
    SqlConnection con = new SqlConnection("server = MUNESH;Database=datastore;UID=sa;Password=123;");
    SqlCommand cmd = new SqlCommand("Select * from data1", con);
    try
   {
        con.Open();
        SqlDataAdapter da = new SqlDataAdapter();
        da.SelectCommand = cmd;
        DataTable dt = new DataTable();
        da.Fill(dt);
        dataGridView1.DataSource = dt;
        con.Close();
    }
    catch (Exception ec)
   {
        MessageBox.Show(ec.Message);
   }


Step(3): Run
Now run your application.
                                                                                                                                             Previous..
                                                                                                                                                Next..

C# program Selection Sorting

Selection sort is a straightforward sorting algorithm. This algorithm search for the smallest number in the elements array and then swap i...