使用csharp将数据库记录绑定到数据网格视图 [英] binding the data base record in to data grid view using csharp

查看:220
本文介绍了使用csharp将数据库记录绑定到数据网格视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

设计如下;



教师代码组合框查看(按钮)





数据网格视图




组合框中的
从数据库中检索所有教师代码并显示在组合框。



工作正常。





当我从组合框中选择教师代码,然后单击视图(按钮),特定的教师代码详细信息将显示在数据网格视图中。







private GlobalFunction GFun = new GlobalFunction();

private SqlDataReader dr;

private string sql;





该代码如下;



sql =从Tb_SCh_TIme_Table选择日期,会话,Faculty_Code其中Course =''+ cb_Faculty_Code.Text +''按日期排序,会话;



dr = GFun.ReadSql(sql);

D. gv_Faculty_Code.DataSource = dr;

//Dgv_Faculty_Code.Databind();



以上Dgv_Faculty_Code.Databind(); Databind(); 。


当我输入Dgv_Faculty_Code时,






之后。数据绑定();这不是为什么。



我怎么能得到它。 databind()。



帮助我。

Design as follows;

Faculty Code Combo box View(Button)


Data grid view


in the combo box all faculty code is retrieved from the data base and display in to the combo box.

it is working fine.


When i select the faculty code from combo box and click the View (Button) the particular Faculty Code details will be display into the data grid view.



private GlobalFunction GFun = new GlobalFunction();
private SqlDataReader dr;
private string sql;


for that code as follows;

sql = "select Date,Session,Faculty_Code from Tb_SCh_TIme_Table where Course = ''" + cb_Faculty_Code.Text + "'' order by Date,session";

dr = GFun.ReadSql(sql);
Dgv_Faculty_Code.DataSource = dr;
//Dgv_Faculty_Code.Databind();

the above Dgv_Faculty_Code.Databind();Databind();.

when i type Dgv_Faculty_Code.


after. databind(); it is not coming why.

how can i get after . databind().

help me.

推荐答案

使用下面的代码,希望它是'对你有帮助





SqlDataAdapter da = new SqlDataAdapter(选择Idno,名字,姓氏,地址,联系方式来自

学生订单由Idno asc,con);



DataSet ds = new DataSet();

da.Fill(ds);

GridView1.DataSource = ds;

GridView1.DataBind();
Using the below code ,Hope It''s helpful to you


SqlDataAdapter da = new SqlDataAdapter("Select Idno,Firstname,Lastname,Address,Contactno from
student order by Idno asc", con);

DataSet ds = new DataSet();
da.Fill(ds);
GridView1.DataSource = ds;
GridView1.DataBind();


这篇关于使用csharp将数据库记录绑定到数据网格视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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