Click here to Skip to main content
15,886,689 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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;

C#
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
Updated 18-Jan-13 2:38am
v2
Comments
[no name] 18-Jan-13 9:14am    
I think you are missing the Bind event here so the data is unable to bind.

1 solution

C#
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();

}
 
Share this answer
 
v2

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900