search data in datagridview using distinct in .net



This is A C# Practice code:
        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 dataentry
        {
            public partial class Distinct : Form
            {
                public Distinct()
                {
                    InitializeComponent();
                }
                string column;
                string orders;
                SqlConnection asdf = new SqlConnection("Data Source=.;Initial Catalog=dataentry;Integrated Security=True;Pooling=False");
                private void button9_Click(object sender, EventArgs e)
                {
                   
                    SqlDataAdapter data = new SqlDataAdapter("Select * from register order by " + textBox1.Text + " " + orders + "", asdf);
                    DataTable ss = new DataTable();
                    data.Fill(ss);
                    dataGridView1.DataSource = ss;
                }

                private void textBox1_TextChanged(object sender, EventArgs e)
                {

                }

                private void radioButton1_CheckedChanged(object sender, EventArgs e)
                {
                    column = "Name";
                }

                private void radioButton3_CheckedChanged(object sender, EventArgs e)
                {

                    column = "Status";
                }

                private void radioButton4_CheckedChanged(object sender, EventArgs e)
                {

                    column = "Salary";
                }

                private void radioButton2_CheckedChanged(object sender, EventArgs e)
                {
                    column = "Gender";
                }

                private void radioButton5_CheckedChanged(object sender, EventArgs e)
                {
                    orders = "asc";
                }

                private void radioButton6_CheckedChanged(object sender, EventArgs e)
                {
                    orders = "desc";
                }
               }
      }

Video For Result:



Share on Google Plus

About Unknown

This is a short description in the author block about the author. You edit it by entering text in the "Biographical Info" field in the user admin panel.
    Facebook Comment