Click here to Skip to main content
15,891,976 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello.
Im trying to do a exercise filter GridView based on selected value in DropDownList.
I have a list of names in dropdownlist and when i click in the name i want that information of persons appears in datagridview.
Im trying do this like this:

C#
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           OleDbConnection con = new OleDbConnection("Data Source=orcl;Persist Security Info=True;User ID=eq;Password=*******;Unicode=True");
           OleDbDataAdapter dataAdapter = new OleDbDataAdapter(String.Format("select * from teacher where idteacher={0} ", idteacher), con);

           DataTable table = new DataTable();
           dataAdapter.Fill(table);
           GridView1.DataSource = table;
          }


but its not working, and "Datatable" object is not recognized buy c#.
Anyone can help me seeing what im doing wrong?
Thanks!
Posted
Updated 11-Jun-13 17:53pm
v2
Comments
Sergey Alexandrovich Kryukov 11-Jun-13 17:22pm    
What do you mean? There is no "database object" in your code.
—SA
PrissySC 11-Jun-13 17:23pm    
Ouch ... you are filling the data each time they click the drop down?

Create a bindingsource and add the data one time.

Fiter and assign to the datagridview based on the dropdown selection. Do this at the very least. :)

There are, however, a zillion ways to deal with the datagridview and filtering. :) Hit the MSDN and read up on filtering the DGV!

Hi
Please be sure about using System.Data namespace and the after that keep in your mind you should call DataBind() method after data source binding in asp.net so I think you forget it:
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
       {
           OleDbConnection con = new OleDbConnection("Data Source=orcl;Persist Security Info=True;User ID=eq;Password=*******;Unicode=True");
           OleDbDataAdapter dataAdapter = new OleDbDataAdapter(String.Format("select * from teacher where idteacher={0} ", idteacher), con);

           DataTable table = new DataTable();
           dataAdapter.Fill(table);
           GridView1.DataSource = table;
           GridView1.DataBind();
          }

At the finally I prefer to you review follow of link:
Five different overloads of the DataAdapter.Fill() method[^]

Best Regards.
 
Share this answer
 
protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
{
string comand = "select * from teacher";
OracleConnection con = new System.Data.OracleClient.OracleConnection();
con.ConnectionString = @"Data Source=orcl;Persist Security Info=True;User ID=eq;Password=***;Unicode=True";
OracleDataAdapter dataAdapter = new OracleDataAdapter(String.Format("select * from teacher where idteacher={0} ", comand), con);

DataTable table = new DataTable();
dataAdapter.Fill(table);
GridView1.DataSource = table;
GridView1.DataBind();
}

Now i have datatable object!
But i got this error in this line : dataAdapter.Fill(table);

Error : ORA-00936: missing expression´

Do you know why can be this error?
 
Share this answer
 

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