OdbcCommand OpenEmp = new OdbcCommand("SELECT EMPLOYEE_GROUP_ASSIGN.EmpNo, EMPLOYEE_PERSONAL.FullName FROM " + "EMPLOYEE_GROUP_ASSIGN INNER JOIN EMPLOYEE_PERSONAL ON EMPLOYEE_GROUP_ASSIGN.EmpNo = EMPLOYEE_PERSONAL.EmpId " + "WHERE (EMPLOYEE_GROUP_ASSIGN.EmpGroupCode = '" + cmbEmpGrup.Text.Trim().ToString() + "')", MainMod.Conn); OdbcDataReader readEmp = OpenEmp.ExecuteReader(); DataTable table = new DataTable(); table.Columns.Add("EmpNo", typeof(string)); table.Columns.Add("FullName", typeof(string)); while (readEmp.Read()) { table.Rows.Add(MainMod.NullableString(readEmp.GetValue(0).ToString()),MainMod.NullableString(readEmp.GetValue(1).ToString())); } readEmp.Dispose(); gvEmployee.DataSource = table;
gvEmployee.columns[0].value = table.columns[0].value // this is what i expting gvEmployee.columns[1].value = table.columns[1].value
gvEmployee.columns[0].HeaderText= "column name"
gvEmployee.columns[0].value = table.columns[0].value
gvEmployee.Columns[0].Datapropertyname = "EmpId"; // or //gvEmployee.Columns[0].Datapropertyname = table.columns[0].Name.ToString();
If you want to manually fill datagridview I suggest to use strong typed datatables and rows from Dataset. In this case you don't have to worry about column names.
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)