Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
when i click the button i want to show the data from the database and display into the datagridview using oledb.

for that code as follows;

C#
       private GlobalFunction GFun = new GlobalFunction();
       private OleDbDataReader oledr;
       private string sql;



  private void Btn_View_Course_Click(object sender, EventArgs e)
     {
       try
       {
 GFun.BindAccessConn();
 sql = "select * from Tb_SCh_TIme_Table where Course = '" +  cb_Course_Name.Text.ToString().Trim() + "'  order by Date,session";
OleDbCommand cmd = new OleDbCommand(sql,GFun.OleDbCon);
cmd.CommandType = CommandType.Text;
OleDbDataAdapter oleda = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
oleda.Fill(dt);
DGV_Course_report.DataSource = dt;
 catch (Exception ex1)
          {
  MessageBox.Show(ex1.ToString(), "Error", MessageBoxButtons.OK);
           }
     }


when i click the button in datagridview records not display.why.

i use the OLEDB conncection.

how can i do.

help me.
Posted
Updated 29-Jan-13 1:35am
v2

1 solution

After this line:
C#
DGV_Course_report.DataSource = dt;


Add below line:
C#
DGV_Course_report.DataBind();


It should work. Reply back if it doesn't.
 
Share this answer
 
Comments
[no name] 29-Jan-13 7:55am    
it is a windows application.

DGV_Course_report.Databind();

in windows application Databind is not coming.

i tried but it is not coming.that is the big problem
what can i do.

in datagridview how to display the record help me.
[no name] 29-Jan-13 8:08am    
please kindly reply help me
Vani Kulkarni 29-Jan-13 8:55am    
Did you try debugging the code using break point? Is the data getting loaded in DataTable dt?
[no name] 29-Jan-13 12:04pm    
DGV_Course_report.DataSource = dt. .Tables[0];

if i write the above code it can work.

when i debug the dt is null why?
[no name] 29-Jan-13 12:04pm    
DGV_Course_report.DataSource = dt. .Tables[0];
if i write the above code it can work?
i can ask question to you. the above code is correct help me.
when i debug the dt is null why?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900