private void SearchForm_Load(object sender, EventArgs e) { dataGridView1.AutoGenerateColumns = false; try { cn = db.createConnection(); if (cn.State == System.Data.ConnectionState.Open) cn.Close(); cn.Open(); cmd = new OleDbCommand("Select BillNo,PartyName,City,State,FORMAT(BillDt,'dd-mm-yyyy')as BillDt from BillMaster", cn); da = new OleDbDataAdapter(cmd); ds = new DataSet(); da.Fill(ds); cn.Close(); } catch (Exception ex) { MessageBox.Show(ex.Message.ToString()); } dataGridView1.AutoGenerateColumns = false; dataGridView1.DataSource = ds.Tables[0]; for (int i = 0; i < ds.Tables[0].Rows.Count; i++) { dataGridView1.Rows[i].Cells[0].Value = ds.Tables[0].Rows[i]["BillNo"].ToString(); dataGridView1.Rows[i].Cells[1].Value = ds.Tables[0].Rows[i]["PartyName"].ToString(); dataGridView1.Rows[i].Cells[2].Value = ds.Tables[0].Rows[i]["City"].ToString(); dataGridView1.Rows[i].Cells[3].Value = ds.Tables[0].Rows[i]["State"].ToString(); dataGridView1.Rows[i].Cells[4].Value = ds.Tables[0].Rows[i]["BillDt"].ToString(); } ds.Dispose(); cmd.Dispose(); da.Dispose(); cn.Close();
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)