Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

How do to display the particular data's in datatable using Datagridview control in c#

$
0
0

Hi all,

Good Day. I'm using C# in Visual Studio 2008. I want to display the particular data's in datagrid view.if I'm using Defaultview i getting full table data's. but i need only particular data's so how can i do?

And my code is Below:

for (int i = 0; i < 9; i++)
                {
                    int pow_tag = Convert.ToInt32(Math.Pow(2, i));
                    //cmd = new SqlCommand("SELECT * from tmessage_temp");
                    string Toqury = "Select fldTo&" + pow_tag + " from tmessage_temp";
                    cmd = new SqlCommand(Toqury, cn);
                    cmd.CommandType = CommandType.Text;
                    Int32 Toqryval = (Int32)cmd.ExecuteScalar();
                    rdr = cmd.ExecuteReader();
                    //Int32 Toinput = rdr.GetInt32(rdr.GetOrdinal("fldTo"));

                    while (rdr.Read())
                    {


                        if (Toqryval == 1)
                        {
                            Datagrdmsgdsp();
                        }
                        if (Toqryval == 2)
                        {
                            Datagrdmsgdsp();
                        }
                        if (Toqryval == 4)
                        {
                            Datagrdmsgdsp();
                        }
}


                    rdr.Close();
                }




private void Datagrdmsgdsp()
        {

string frmqry = "SELECT fldMmsg  from tmessage_temp";
                cmd = new SqlCommand(frmqry, cn);
                cmd.CommandType = CommandType.Text;
                string newfrmqry = "";
                newfrmqry = cmd.ExecuteScalar().ToString();
                SqlDataAdapter sdr1 = new SqlDataAdapter(cmd);
                DataTable dt1 = new DataTable();
                sdr1.Fill(dt1);
                dataGridView1.DataSource = dt1.DefaultView;



                string toqry = "SELECT fldSmsg from tmessage_temp";
                cmd1 = new SqlCommand(toqry, cn);
                cmd1.CommandType = CommandType.Text;
                string newtoqry = "";
                newtoqry = cmd.ExecuteScalar().ToString();
                SqlDataAdapter sdr2 = new SqlDataAdapter(cmd1);
                DataTable dt2 = new DataTable();
                DataSet ds = new DataSet();
                sdr2.Fill(dt2);
                dataGridView2.DataSource = dt2.DefaultView;
}


Thanks & Regards Sasi ................. Go Green


Viewing all articles
Browse latest Browse all 2535

Trending Articles



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