Click here to Skip to main content
15,887,683 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Here is my code where I am getting an error that says Unhandled by the user.

string connection =  "Data Source=C:\\Documents andSettings\\Administrator\\My Documents\\my1.mdb";
string cl = DropDownList1.SelectedItem.Text;
string query= "Select * from fee where course='cl'"; AccessDataSource ads = new AccessDataSource("C:\\Documents and Settings\\Administrator\\My Documents\\my1.mdb", query);
GridView1.DataSource = ads;
GridView1.DataSourceID = String.Empty;
GridView1.DataBind();


Here I want to get string from dropdownlist. And in database there is one coloum named course. I want to fetch data for that particular course.

[edit]Code block added, "Ignore HTML..." option disabled - OriginalGriff[/edit]
Posted
Updated 27-Mar-11 21:33pm
v3

1 solution

You need to change like below to pass the dropdown list value to database. Below in highlighted with underline.

MIDL
string connection = "Data Source=C:\\Documents andSettings\\Administrator\\My Documents\\my1.mdb";
          string cl = DropDownList1.SelectedItem.Text;
          string query = "Select * from fee where course=" + c1; AccessDataSource ads = new AccessDataSource("C:\\Documents and Settings\\Administrator\\My Documents\\my1.mdb", query);
          GridView1.DataSource = ads;
          GridView1.DataSourceID = String.Empty;
          GridView1.DataBind();


Hope it helps.
 
Share this answer
 
Comments
abhiamity86 28-Mar-11 4:14am    
Thanks For helping me.
But it is again giving same exception.
abhiamity86 28-Mar-11 4:34am    
My main issue is when i am writing exactely course name rather than variable then it is working fine.
But when i use variable then it is giving exception.
Pls help me.
Thanks In Advance.
That's Aragon 28-Mar-11 5:44am    
There might be some reason for this kind of issue.
1) Make sure dropdown list values are same as course column in the database. i.e. no spelling mistake in that.
2) Debug the source code and get the "c1" i.e. dropdown selected item text. Make sure that is what you are going to search for.
3) Please post your exception, so that one can help you better way.

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