Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/311.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/oop/2.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# 如何使用c将数据从局部变量传递到datagridview#_C#_Datagridview - Fatal编程技术网

C# 如何使用c将数据从局部变量传递到datagridview#

C# 如何使用c将数据从局部变量传递到datagridview#,c#,datagridview,C#,Datagridview,如何在datagridview中传递计算结果的值。在下面的代码中,我通过DataTable从数据库中获取的值填充了网格的两列,然后添加了一个名为“Text”的新列。现在我想在这个列中传递我计算的哈希值,但是可能有语法问题或错误导致错误发生。以下是我的代码 SqlDataAdapter sda = new SqlDataAdapter("Select Image,Hash from UserInput where PINCODE = '" + txt_LPin.Text + "'",conn);

如何在datagridview中传递计算结果的值。在下面的代码中,我通过DataTable从数据库中获取的值填充了网格的两列,然后添加了一个名为“Text”的新列。现在我想在这个列中传递我计算的哈希值,但是可能有语法问题或错误导致错误发生。以下是我的代码

SqlDataAdapter sda = new SqlDataAdapter("Select Image,Hash from UserInput where PINCODE = '" + txt_LPin.Text + "'",conn);
DataTable dt = new DataTable();
sda.Fill(dt);
dataGridView1.DataSource = dt;
int nOr = dataGridView1.Rows.Count;
if (nOr == 5)
{
     LoginCluePoint lcp = new LoginCluePoint();
     lcp.dgv_LCP.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill;
     lcp.dgv_LCP.RowTemplate.Height = 101;
     lcp.dgv_LCP.DataSource = dt;               

     DataGridViewColumn col = new DataGridViewTextBoxColumn();
     col.HeaderText = "Text";
     int colIndex = lcp.dgv_LCP.Columns.Add(col);
     lcp.dgv_LCP.Columns[2].Visible = false;
}

此问题由以下代码解决

DataGridViewColumn col = new DataGridViewTextBoxColumn();
col.HeaderText = "Text";
int colIndex = lcp.dgv_LCP.Columns.Add(col);
dgv_LCP.Rows[0].Cells[2].Value = hash     
lcp.dgv_LCP.Columns[2].Visible = false;

出现了什么错误?我缺少此行dgv_LCP。行[0]。单元格[2]。值=哈希;