Search select statement

sql statement search-engine

Page 1 of 1

1 Replies - 1179 Views - Last Post: 02 November 2009 - 07:59 AM Rate Topic: -----

#1 husna_   User is offline

  • New D.I.C Head

Reputation: 1
  • View blog
  • Posts: 9
  • Joined: 07-September 09

Search select statement

Post icon  Posted 31 October 2009 - 07:02 PM

I am creating a page which would have different field for the user to search from.

E.g. search by:
Grade: -dropdownlist1-
Student name: -dropdownlist2-
Student ID: -dropdownlist3-
Lessons: -dropdownlist4-
Year: -dropdownlist5-

How do i write the select statement for this.
Each dropdownlist would need a select statement which would extract out different data from the database.
But, I want to write ONE select statement which can dynamically choose the dropdownlist options.
Instead of writing many many select statement.

Lets say;
Grade: -dropdownlist1- ; default value(all)
Student name: -dropdownlist2-; default value(all)
Student ID: -dropdownlist3-; 0-100 is choosen
Lessons: -dropdownlist4-; A-C is choosen
Year: -dropdownlist5-; 2009 is choosen

Is This A Good Question/Topic? 0
  • +

Replies To: Search select statement

#2 ramesh866   User is offline

  • D.I.C Head

Reputation: 2
  • View blog
  • Posts: 91
  • Joined: 03-October 09

Re: Search select statement

Posted 02 November 2009 - 07:59 AM

ya you can do with switch statement. say
 protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
		string app = ConfigurationManager.ConnectionStrings["masterConnectionString"].ConnectionString;
		SqlConnection cn = new SqlConnection(app);
		switch (DropDownList1.SelectedValue)
			case "name":
				SqlCommand cmd = new SqlCommand("select names from asp", cn);
				SqlDataReader dr = cmd.ExecuteReader();
				while (dr.Read())
					Response.Write(dr [0]);
			case "id":
				SqlCommand cmd1 = new SqlCommand("select id from asp", cn);
				SqlDataReader dr1 = cmd1.ExecuteReader();
				while (dr1.Read())


here i just made the data displayed in write statement. you can bind it any control as per your requriment
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1