1
디자인 타임에 열이 정의 된 코드를 통해 눈금을 사용하고 있습니다.그리드에 데이터가 표시되지 않는 이유는 무엇입니까?
) (의 Form_Load 그리드 래핑 내 코드 : I 프로그램을 디버깅 데이터를 디버깅하는 동안 직접 창으로부터 관찰되는 각각의 필드에 할당되지만 형태
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();
}
데이터가 표시되지 않습니다. 그리고 데이터 집합에서 가져온 빈 행 수가 생성됩니다.
어떻게 해결할 수 있습니까? 도와주세요.
여기서 dataGridView1.DataBind()가 있습니다. – Sajeetharan