Keerthika Reddy

Keerthika Reddy

  • NA
  • 21
  • 616

Object reference not set to an instance of an object

Nov 12 2018 1:56 AM
private void GetColumns(string key, DataGridView dataGrid)
{
string strQuery = string.Format("select col_index, col_name, display_name, col_type, visible, col_width from rayonpos.datagridcolumns where source_key = '{0}' order by col_index", key);
DataTable dtColumns = DataService.ExecuteQueryAndReturnTable(strQuery);
if (dtColumns.Rows.Count > 0)
{
dataGrid.Columns.Clear();
foreach (DataRow dtRow in dtColumns.Rows)
{
DataGridViewColumn dgvCol = null;
if (dtRow["col_type"].ToString().ToUpper() == "TEXT")
{
dgvCol = new DataGridViewTextBoxColumn();
}
dgvCol.Name = dtRow["col_name"].ToString();
dgvCol.HeaderText = dtRow["display_name"].ToString();
dgvCol.Visible = Convert.ToBoolean(dtRow["visible"]);
dgvCol.Width = Convert.ToInt16(dtRow["col_width"]);
dataGrid.Columns.Insert(Convert.ToInt16(dtRow["col_index"]), dgvCol);
}
}
}

Answers (3)