当我单击按钮时,我想显示数据库中的数据并使用oledb显示到datagridview中 [英] when i click the button i want to show the data from the database and display into the datagridview using oledb

查看:64
本文介绍了当我单击按钮时,我想显示数据库中的数据并使用oledb显示到datagridview中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我点击按钮时我想显示数据库中的数据并使用oledb显示到datagridview中。



代码如下;



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;

       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);
           }
     }





当我点击datagridview记录中的按钮时不显示。



i使用OLEDB conncection。



我该怎么办。



帮助我。



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

i use the OLEDB conncection.

how can i do.

help me.

推荐答案

在这一行之后:

After this line:
DGV_Course_report.DataSource = dt;





添加以下行:



Add below line:

DGV_Course_report.DataBind();





它应该有效。如果不是,请回复。



It should work. Reply back if it doesn''t.


这篇关于当我单击按钮时,我想显示数据库中的数据并使用oledb显示到datagridview中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆