本文介绍了我想通过使用20.-30之间的搜索条件来查找特定年龄组的成员,这些条件由asp.net中的dropdownlistbox维护的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用asp.net的dropdownlistbox中维护的搜索条件(例如"20至30之间")来查找年龄组成员

我必须实施在婚姻区中查找某些年龄段的成员"

我怎么能为此写代码.....

没有维护数据库中的年龄字段,我如何检索特定的年龄组成员...?

I want to find age group members by using searching criteria like "between 20 to 30 " which are maintained in dropdownlistboxes in asp.net

i have to implement this "finding certain age group members in Matrimony sites"

how can i write code for this.....

with out maintaining age field in database how can i retrieve particular age group members...?

推荐答案

SELECT * FROM myTable WHERE birthdate <= '1-1-1992' AND birthdate >= '1-1-1982'


如果在C#中执行此操作,则只需使用参数化查询:


If you are doing this in C#, then just use a parametrised query:

using (SqlConnection con = new SqlConnection(strConnect))
    {
    con.Open();
    using (SqlCommand com = new SqlCommand("SELECT * FROM myTable WHERE birthDate>=@MINDATE AND birthDate <=@MAXDATE", con))
        {
        DateTime now = DateTime.Now;
        com.Parameters.AddWithValue("@MINDATE", now.AddYears(-30));
        com.Parameters.AddWithValue("@MAXDATE", now.AddYears(-20));
        using (SqlDataReader reader = com.ExecuteReader())
            {
            while (reader.Read())
                {
                ...
                }
            }
        }
    }


这篇关于我想通过使用20.-30之间的搜索条件来查找特定年龄组的成员,这些条件由asp.net中的dropdownlistbox维护的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-31 00:37