Datagridview以空行返回 [英] Datagridview returned with empty row

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

问题描述

今天我遇到填写datagridview1的问题。我已创建void以从数据源填充gridview。如果我把它推到页面加载,它在按钮点击工作正常但不填写。



我尝试过:



Today i am facing problem to fill datagridview1. i have created void for fill the gridview from data source. it is working fine in buttons click but not fill if i putted it to the page load.

What I have tried:

private void fillgidview()
        {
            try
            {
                cnn.Open();
                string sqlcommand = " select OPD_NO as [OPD No],Patientname as [Pateint Name],Age,VisitDate as [visit Date],Department,Consultent_Doctor  from OPD_table  where Status_pet='Checked In'   and Consultent_Doctor='" + label5.Text + "'";

                SqlDataAdapter adap = new SqlDataAdapter(sqlcommand, cnn);

                DataTable dt = new DataTable();

                adap.Fill(dt);
                
                this.dataGridView1.DataSource = dt;
                
                cnn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.ToString());

            }
        }

推荐答案

参考 - 如何:将数据绑定到Windows窗体DataGridView控件 [< a href =https://msdn.microsoft.com/en-us/library/fbk67b6z%28v=vs.110%29.aspx?f=255&MSPPError=-2147217396target =_ blanktitle =New窗口> ^ ]。



确保您的数据来自数据库。
Refer - How to: Bind Data to the Windows Forms DataGridView Control[^].

Make sure your data is coming from database.


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

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