使用Windows应用程序在c#.net中的datagridview中加载数据 [英] load data in datagridview in c#.net using windows application

查看:49
本文介绍了使用Windows应用程序在c#.net中的datagridview中加载数据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Windows应用程序在c#.net中的datagridview中加载数据。





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


组合框中的
将从数据库中显示所有教师代码。工作正常。



当我选择教师代码并点击视图(按钮)想要在datagridview中显示所选的教师代码。



为此我写了如下代码;



load data in datagridview in c#.net using windows application.


Faculty Code Combo box View (Button)

in combo box all faculty code will be displayed from the data base. working fine.

when i select the faculty code and click the view (Button) want to display selected faculty code in datagridview.

for that i written the code as follows;

private void Btn_View_Faculty_Click(object sender, EventArgs e)
        {
  sql = "select CONVERT(varchar(11), Date, 106)  AS Date_of_birth,Session,Faculty_Code from Tb_SCh_TIme_Table where Course = ' " + cb_Course_Name.Text + ' " order by Date,session";
            SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);

            SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);

            DataTable table = new DataTable();

            dataAdapter.Fill(table);

            bindingSource2.DataSource = table;

            Dgv_Faculty_Code.DataSource = bindingSource2;
        }





当我跑步并选择教师代码并点击查看按钮时。
数据网格视图中的


未显示选定的教师代码详细信息。



为什么?从上面形成我的错误。我试过但它不起作用。



when i run and select the faculty code and click the view button.

in data grid view the selected faculty code details is not displaying.

why? form my above what is the mistake. i tried but it is not working.

推荐答案

private void Btn_View_Faculty_Click(object sender, EventArgs e)
{
sql = "select CONVERT(varchar(11), Date, 106) AS Date_of_birth,Session,Faculty_Code from Tb_SCh_TIme_Table where Course = ' " + cb_Course_Name.Text + ' " order by Date,session";
SqlDataAdapter dataAdapter = new SqlDataAdapter(sql, con);
 
SqlCommandBuilder commandBuilder = new SqlCommandBuilder(dataAdapter);
 
DataTable table = new DataTable();
 
dataAdapter.Fill(table);
 
YourGridViewName.DataSource = table;
YourGridViewName.DataBind();

}


这篇关于使用Windows应用程序在c#.net中的datagridview中加载数据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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