private void grid() { dgv.Columns.Clear(); DataGridViewTextBoxColumn dgvCol = new DataGridViewTextBoxColumn(); string str; str = "SELECT * FROM excess"; OdbcCommand cmd = new OdbcCommand(str,con); OdbcDataAdapter da = new OdbcDataAdapter(); DataSet ds = new DataSet(); da.SelectCommand = cmd; da.Fill(ds, "ExcessGView"); if (ds.Tables["ExcessGView"].Rows.Count > 0) { foreach (DataRow dr in ds.Tables["ExcessGView"].Rows) { for (int i = 0; i < ds.Tables["ExcessGView"].Columns.Count; i++) { dgvCol = new DataGridViewTextBoxColumn(); dgvCol.Width = 150; dgvCol.ReadOnly = true; dgvCol.SortMode = DataGridViewColumnSortMode.Programmatic; dgvCol.HeaderText = ds.Tables["ExcessGView"].Columns[i].ColumnName.ToUpper(); dgv.Columns.Add(dgvCol); } break; } int r = 0; dgv.RowCount = ds.Tables["ExcessGView"].Rows.Count; foreach (DataRow dr in ds.Tables["ExcessGView"].Rows) { for (int i = 0; i < ds.Tables["ExcessGView"].Rows.Count; i++) { try { dgv.Rows[r].Cells[i].Value = dr[i].ToString(); } catch (Exception ex) { con.Close(); MessageBox.Show(ex.Message); } } r = r + 1; } } else { con.Close(); } }
dgv.DataSource=ds.Tables["ExcessGView"];
mydg.Datasource = ds.Tables["mytable"]; mydg.Databind();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)