Saturday 3 May 2014

How to use OpenFile Dialog and Copy that path


                                                                                                                                         Previous
                                                                                                                                              Next..
Here i will explain How to use OpenFile Dialog and Copy that path.

Step(1):Form
Drag and down a button and write its text as "Open".
Step(2):Code
Double click on button and write this code.

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

private void Button1_click(object sender, EventArgs e)
{
OpenFileDialog openfile = new OpenFileDialog ();

if(openfile .ShowDialog() ==System.Window.Forms.DialogResult.OK)
{
string strfilename = openfile .FileName;
MessageBox.show(strfilename);
}
}
Step(3):Output
Now run your application.
                                                                                                                                         Previous
                                                                                                                                              Next..

Friday 2 May 2014

How to use DateTime Picker and save in database in window form


                                                                                                                                          Previous
                                                                                                                                            Next...
Here i will explain how to DateTime Picker and how to save its value in database.
Step(1):- Form
Drag and down a Datetime Picker from ToolBox. and go its property and set "Custom Format" as
"yyyy-mm-dd".and other property "Formate" as  "custom".

Step(2):- code

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

String gender;                                                              //we have to define this
        private void button1_Click(object sender, EventArgs e)
        {
           SqlConnection con = new SqlConnection(str);
                String str = "server=MUNESH-PC;database=windowapp;UID=sa;password=123";
                String query = "insert into data (E.id,name,surname,age,gender,DOB) values ('"+this.eid_txt.text+"','"+this.nametxt.text+"','"+this.surname_txt.text+"','"+this.age_txt.text+"' , '"+this.gender+"' , '"+this.DateTimePicker1.Text+"')";
     SqlCommand cmd = new sqComamnd(query,con);         
  SqlDataReader dbr;
                       
               try
              {
               con.open();
               dbr = cmd.ExecuteReader();
                MessageBox.Show("saved");
              while(dbr.read())
             {
                 
              }
            }
            catch (Exception es)
            {
                MessageBox.Show(es.Message);

            }
        }
private void rediobutton1.checked(object sender, EventArgs e)
{
gender = "male";
}
private void rediobutton1.checked(object sender, EventArgs e)
{
gender = "female";
}
    }
} 

Step(3):- Output
Run your application

                                                                                                                                          Previous
                                                                                                                                            Next...

Thursday 1 May 2014

How to use CheckBox and redio Button in window form


                                                                                                                                           Previous..
                                                                                                                                               Next..

Here i will explain that how to use checkBox and Redio Button in window form when we insert data into database.

Step(1):Form
Drag and down two redio button for male and female. You can see my tutorial 6 that how to insert data into database.
Step(2):Code
Coding is same as tutorial 6 only difference is for redio button.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

String gender;                                                              //we have to define this
        private void button1_Click(object sender, EventArgs e)
        {
           SqlConnection con = new SqlConnection(str);
                String str = "server=MUNESH-PC;database=windowapp;UID=sa;password=123";
                String query = "insert into data (E.id,name,surname,age,gender) values ('"+this.eid_txt.text+"','"+this.nametxt.text+"','"+this.surname_txt.text+"','"+this.age_txt.text+"' , '"+this.gender+"')";
     SqlCommand cmd = new sqComamnd(query,con);         
  SqlDataReader dbr;
                       
               try
              {
               con.open();
               dbr = cmd.ExecuteReader();
                MessageBox.Show("saved");
              while(dbr.read())
             {
                 
              }
            }
            catch (Exception es)
            {
                MessageBox.Show(es.Message);

            }
        }
private void rediobutton1.checked(object sender, EventArgs e)
{
gender = "male";
}
private void rediobutton1.checked(object sender, EventArgs e)
{
gender = "female";
}
    }
} 

//You can do this for check box.
Step(3):Output
Now run your application.
                                                                                                                                           Previous..
                                                                                                                                               Next..

Wednesday 30 April 2014

Display selected Row from datagrid view to textBoxes in window application


                                                                                                                                               Previous..
                                                                                                                                                  Next..

Here i will explain how display selected row from datagrid view to textboxes.

Step(1):- Form..
Drag and down a datagrid view and textboxes.For this you see tutorial6 and tutorial14. From these tutorial you will learn how insert data in database and how to show database data in datagridview.

Step(2):- Code..
Click on DataGrid View and write this code.
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace First_Csharp_app
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();

        }

private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    SqlConnection con = new SqlConnection("server = MUNESH\\SQL2008R2;Database=data;UID=sa;Password=123;");
   
  if(e.RowIndex >=0)
{
  
   DataGridViewRow row = this.datagridview1.Rows[e.RowIndex];
    if (cell != null)
    
        id_txt.Text = row.Cells["ID"].Value.ToString();
       textBox1.Text = row.Cells["FirsName"].Value.ToString();
       textBox1.Text = row.Cells["LastName"].Value.ToString();
        textBox3.Text = row.Cells["Age"].Value.ToString();
    }
}

Step(3):- Output..
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...