简体   繁体   中英

How to pass data from local variable to datagridview using c#

How do I pass value of my calculated result in datagridview. In the following code I filled the 2 columns of grid by the values fetched from database through DataTable, then I add a new column named "Text". Now I want to pass a value of my calculated hash in this column but there may b some syntax problem or some mistake which causes an error occurred. Following is my code;

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;
}

This problem is resolved by the following code

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM