Quantcast
Channel: ฟอรัม Getting started with SQL Server
Viewing all articles
Browse latest Browse all 8428

how to view all records in the database having same values in all the rows

$
0
0

I have two rows with the same Eno...i want to view both the enos in ma gridview

Following is ma code:

 try
            {
                conn = new SqlConnection(@"Data Source=RAMESH\SQLEXPRESS;Initial Catalog=Payroll;Integrated Security=True");
                conn.Open();
                query = "Select count(Eno) from EmpLeave group by Eno having count(Eno)>1";

                cmd = new SqlCommand(query, conn);

                dr = cmd.ExecuteReader();
                if (dr.Read())
                {
                    conn.Close();
                    DataSet ds = new DataSet();
                    conn.Open();
                    strsql = "Select count(Eno) from EmpLeave group by Eno having count(Eno)>1";
                    SqlDataAdapter ad = new SqlDataAdapter(strsql, conn);
                    ad.Fill(ds);
                    conn.Close();
                    dataGridView1.DataSource = ds.Tables[0];
                    //dataGridView1.DataBindingComplete();
                    //GridView1.DataSource = ds.Tables[0];
                    //GridView1.DataBind();

                }
                else
                {
                    MessageBox.Show("No more entries");
                }
                dr.Close();
                conn.Close();
            }

            catch (Exception exc)
            {
                MessageBox.Show(exc.Message);
            }


Viewing all articles
Browse latest Browse all 8428

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>