行数 [英] Count Of Rows

查看:109
本文介绍了行数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好

我正在C#窗口应用程序中使用datagridview.
我想计算一下runtim的datagridview中有多少行.


我将数据附加到数据库的datagridview中.

请帮帮我.

在Advance中致谢

Hello

I am using a datagridview in a C# window application.
I want to count how many rows in datagridview in runtim.


I attach data in datagridview of database.

Please Help me.

Thanks in Advance

推荐答案

要获取行数,您要做的就是检查DataGridView的属性 RowCount
To get the Row Count all you have to do is check the property RowCount of the DataGridView


DataGridView.RowCount属性 [ ^ ]


您好,Kahlid先生,她的解决方法
下面的代码写在组合框中,选定的索引更改可以在单击按钮时写入,它将计算网格视图中存在的总行数,并将其打印在消息框中

Hello Mr.Kahlid her''s your solution
The below code is written in combobox selected index change u can write it in button click, it will count the total number of rows present in grid view and print it in a messagebox

 private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
        {
            int x=0;
            SqlConnection connect = new SqlConnection();
            connect.ConnectionString = "Data Source=.;Initial Catalog=RJIT;Integrated Security=True";
            connect.Open();
            string mycommand = "select * from Inquiry_Table where time_of_inquiry=''" + comboBox1.Text + "''";
            SqlCommand cmd = new SqlCommand(mycommand, connect);
            SqlDataAdapter adp = new SqlDataAdapter();
            adp.SelectCommand = cmd;
            DataSet ds = new DataSet();
            DataTable dt;
            adp.Fill(ds);
            dt = ds.Tables[0];
            SqlDataReader dr = cmd.ExecuteReader();
            while (dr.Read() == true)
            {
                dataGridView1.Visible = true;
                dataGridView1.DataSource = dt; //binding datagrid with data
                x = x + 1; //Increment the value of x         
            }
//printing total count
            MessageBox.Show("Total Inquiry found " + x.ToString(),"Information",MessageBoxButtons.OK,MessageBoxIcon.Information);
            connect.Close();

        }



一旦找到有用的答案,就对我的答案进行评分

谢谢&问候
基数:)



Do rate my answer once u find it useful

Thanks & Regards
Radix :)


这篇关于行数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆