使用csharp将数据库检索到数据网格视图 [英] retrieving the data base in to data grid view using csharp

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

问题描述

我试过但它不起作用。



教师代码组合框视图(按钮)





private void Btn_View_Course_Click(object sender,EventArgs e)

{

sql =从Tb_SCh_TIme_Table选择日期,会话,课程,其中Faculty_Code = ''+ Cb_Faculty_Code.Text +''按日期,会话顺序;





DataTable dt = new DataTable();

SqlDataAdapter da = new SqlDataAdapter(sql,con);

SqlCommandBuilder cmd = new SqlCommandBuilder(da);

da.Fill(dt) ;

dataGridView1.DataSource = dt;

}


数据库记录中有


。特定的Faculty_Code详细信息要显示在datagridview1中。



选择Faculty_Code并单击视图(按钮)。



在datagridview1中,Faculty_Code详细信息未显示在数据网格视图中。


$ b $从我的代码看来,b是我的错误。我可以这样做。

i tried but it is not working.

Faculty Code combo box view(Button)


private void Btn_View_Course_Click(object sender, EventArgs e)
{
sql = "select Date,Session,Course from Tb_SCh_TIme_Table where Faculty_Code= '' " + Cb_Faculty_Code.Text + "''order by Date,session ";


DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sql, con);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
da.Fill(dt);
dataGridView1.DataSource = dt;
}

in the data base records are there.

when i select the Faculty_Code and click the View Button .the particular Faculty_Code details want to display in datagridview1.

select the Faculty_Code and click the view (Button).

in the datagridview1 the Faculty_Code details is not display in the data grid view.

from my code wat is the mistake.how can i do.

推荐答案

你应该将数据绑定到数据网格视图。



you should bind data to the data grid view.

private void Btn_View_Course_Click(object sender, EventArgs e)
{
sql = "select Date,Session,Course from Tb_SCh_TIme_Table where Faculty_Code= '' " + Cb_Faculty_Code.Text + "''order by Date,session ";
 

DataTable dt = new DataTable();
SqlDataAdapter da = new SqlDataAdapter(sql, con);
SqlCommandBuilder cmd = new SqlCommandBuilder(da);
da.Fill(dt);
dataGridView1.DataSource = dt;
dataGridView1.DataBind();
}





希望这对你的问题有所帮助。



Hope this will help u on ur problem.


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

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