Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/reporting-services/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Datagridview不显示数据_C#_Winforms_Datagridview - Fatal编程技术网

C# Datagridview不显示数据

C# Datagridview不显示数据,c#,winforms,datagridview,C#,Winforms,Datagridview,我有两个数据网格视图(ValidationRun是主视图,结果是详细视图)。我将其绑定到一个数据集,我知道该数据集包含数据-我可以在调试时看到它。但是,我没有在网格中获取数据 有什么想法吗 /class level objects private DataGridView dgvValidationRun = new DataGridView(); private BindingSource bsValidationRun = new BindingSource(); private DataG

我有两个数据网格视图(ValidationRun是主视图,结果是详细视图)。我将其绑定到一个数据集,我知道该数据集包含数据-我可以在调试时看到它。但是,我没有在网格中获取数据

有什么想法吗

/class level objects
private DataGridView dgvValidationRun = new DataGridView();
private BindingSource bsValidationRun = new BindingSource();
private DataGridView dgvResults = new DataGridView();
private BindingSource bsResults = new BindingSource();

private void Form1_Load(object sender, EventArgs e)    
    {    

        // Bind the DataGridView controls to the BindingSource    
        // components and load the data from the database.    
        dgvValidationRun.DataSource = bsValidationRun;    
        dgvResults.DataSource = bsResults;    
        GetData();    

        // Resize the master DataGridView columns to fit the newly loaded data.    
        dgvValidationRun.AutoResizeColumns();    

        // Configure the details DataGridView so that its columns automatically    
        // adjust their widths when the data changes.    
        dgvResults.AutoSizeColumnsMode =    
            DataGridViewAutoSizeColumnsMode.AllCells;    

    }

private void GetData()    
    {    
        try    
        {    
            SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["XMLValidate.Properties.Settings.ValidationResultsConnectionString"].ConnectionString);    

            // Create a DataSet.    
            DataSet data = new DataSet();    
            data.Locale = System.Globalization.CultureInfo.InvariantCulture;    

            // Add data from the Customers table to the DataSet.    
            SqlDataAdapter daValidationRun = new SqlDataAdapter("select * from ValidationRun", connection);    
            daValidationRun.Fill(data, "ValidationRun");    

            // Add data from the Orders table to the DataSet.    
            SqlDataAdapter daResults = new SqlDataAdapter("select * from Result", connection);    
            daResults.Fill(data, "Result");    

            // Establish a relationship between the two tables.    
            DataRelation relRunResult = new DataRelation("RunResult",    
                data.Tables["ValidationRun"].Columns["RunId"],    
                data.Tables["Result"].Columns["RunId"]);    
            data.Relations.Add(relRunResult);    

            // Bind the run data connector to the Run table.    
            bsValidationRun.DataSource = data;    
            bsValidationRun.DataMember = "ValidationRun";    

            // Bind the results data connector to the results data connector,    
            // using the DataRelation name to filter the information in the     
            // details table based on the current row in the master table.     
            bsResults.DataSource = bsValidationRun;    
            bsResults.DataMember = "RunResult";    

            dgvValidationRun.AutoGenerateColumns = true;    
            dgvValidationRun.Refresh();    
        }    
        catch (Exception ex)    
        {    
            int i = 1;    
        }    
    }

非常感谢nawfal,这就是问题所在。我有两个数据网格,我已经通过设计器添加到表单中,但是忘记给它们起与隐藏代码相同的名称-doh

是否将dgvValidationRun添加到表单控件中?我怀疑有一些非常琐碎的事情,请删除捕获并查看是否出现异常。非常感谢nawfal,这就是问题所在。我有两个数据网格,我已经通过设计器添加到表单中,但是忘记给它们起与隐藏代码相同的名称-doh!