How to Pass Dropdownlist Value to Sql Query?


I want to pass dropdownlist which select the value and pass to the SQL query,But I don't have idea that how can I do to the next step.


List<SelectListItem> List = new List<SelectListItem>();
minList.Add(new SelectListItem {
minList.Add(new SelectListItem
    Text = DateTime.Now.AddMinutes(-2).ToString(),
    Value = "2"
minList.Add(new SelectListItem
    Text = DateTime.Now.AddMinutes(-3).ToString(),
    Value = "3"
});}@Html.DropDownList( "Min",List, "Select")

SQL Statement(C#):

string sqlStr = "Select * From Data WHERE Time BETWEEN @A AND @B";
SqlCommand cmd = new SqlCommand(sqlStr, conn);

DateTime now = DateTime.Now;
SelectListItem min = new SelectListItem();
cmd.Parameters.Add(new SqlParameter("@A", min.Value));
cmd.Parameters.Add(new SqlParameter("@B", now));


In your controller Action Method, you can use FormCollection or Request.Form to get dropdown value.

string strDDLValue = Request.Form["minList"].ToString();
By : Vicky

You can debug your mongo queries in multiple ways.

Start with your index usage using below command :
db.images.aggregate( [ { $indexStats: { } } ] )

If this don't give you any useful information, then check the execution plan of the slow queries using : db.setProfilingLevel(2)

db.system.profile will give you complete profile of your queries.

C++11 solution:

#include <type_traits>

template<typename From, typename To>
To map(From e) {
    return static_cast<To>(
        static_cast<typename std::underlying_type<To>::type>(
        static_cast<typename std::underlying_type<From>::type>(e)));

This casting cascade is very explicit and supports enum classes.

For older C++ versions and for enums without class, static_cast<Enum2>(e) would suffice.


With template specialization, you can use map without specifying any types explicitly:

enum class Enum1: int {A, B, C, D};
enum class Enum2: char {A1, B1, C1, D1};

template<typename T>
struct target_enum {

struct target_enum<Enum1> {
    typedef Enum2 type;

template<typename From>
typename target_enum<From>::type map(From e) {
    typedef typename target_enum<From>::type To;
    return static_cast<To>(
        static_cast<typename std::underlying_type<To>::type>(
        static_cast<typename std::underlying_type<From>::type>(e)));

You can then call map(Enum1::A). Also works with simple, non-class enums.

By : flyx

This video can help you solving your question :)
By: admin