Click here to Skip to main content
12,449,891 members (29,878 online)
Rate this:
 
Please Sign up or sign in to vote.
See more: C#
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.
Posted 18-Jan-13 2:17am
Updated 18-Jan-13 2:38am
v2

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

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();
 
}
  Permalink  
v2

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

  Print Answers RSS
Top Experts
Last 24hrsThis month


Advertise | Privacy | Mobile
Web02 | 2.8.160826.1 | Last Updated 18 Jan 2013
Copyright © CodeProject, 1999-2016
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100