ASP.NET 中按字母、数字和数字进行高级排序实现人物

发布于 2024-10-02 06:58:19 字数 1197 浏览 0 评论 0原文

我想根据多种因素对我的记录进行某种排序 比如姓名、年龄......所以到目前为止我所完成的是创建一个用户控件来显示数据库中的因素(姓名 | 城市) 因此,当我单击“名称”时,它会使用所有字母表和“其他字符”填充中继器,以显示以数字或其他字符开头的名称 当单击“城市”时,中继器中会填充我数据库中的所有城市,

我认为城市排序很容易,但我现在正在研究名称排序。

现在我希望我能在这一点上找到帮助:

1 - 就我实现而言,您认为这是一个好的实现吗..它是否是优化数据库负载的最佳选择


2 - 我使用了这个查询“SELECT [id ], [name] FROM list WHERE (name like @SearchString + '%' ) 并且搜索字符串是从查询字符串中检索的,该查询字符串等于我想要排序的字母但是如何返回所有以数字或其他开头的名称字符,我的意思是我不想在我的字母列表旁边列出所有字符和数字的列表:S!

编辑第 2 点!

我已经设法得到了“其他”按钮通过使用通配符格式名称如'[^az]%'成功过滤所有不以字母(数字或特殊字符)开头的记录我希望它对其他人有帮助


3 ! - 我已将中继器放置在 Page.aspx 中,然后将其绑定到 SqlDataReader 对象,而不是在代码隐藏文件中使用 SqlDataSource,我认为最好控制打开和关闭连接并处理错误,因为我使用SqlDataSource时无法知道连接发生了什么!,如果我错了请指正,我刚刚花了1个月练习!无论如何,当我第一次使用 SqlDataSource 时,我可以轻松地为参数提供默认值,这样我就不会收到错误,因为需要填充显示转发器,并且当第一次加载页面时,它是干净的,没有查询字符串,但我找不到现在,当我使用一些 ADO.NET 类并作为中继器的数据源时,SqlDataReader 对象

    <SelectParameters>
    <asp:QueryStringParameter Name="arrange_by_id" QueryStringField="ID" 
        Type="Int32" DefaultValue="1" />
    </SelectParameters>

P.SI 考虑使用 RegEx 来过滤以数字或字符开头的所有记录,它就像 sql 通配符,但有更多的进步,问题是我不知道它是否可以在这种情况下使用或如何在我的查询中使用它

I want to implement some kind of sorting against my records, according to many factors
like name, age...so what I've accomplished so far is creating a User Control to display the factors (Name | City ) from the database
so when I click on "Name" it populates a repeater with all the alphabet plus "Other Characters" to display the names that start with number or other characters
and when click on "City" the repeater is populated with all the cities I have in my database

the city sorting is easy i think, but I'm now I'm working on the name sorting.

Now I hope I'd find help with this points :

1 - As far I implemented, do you think it's a good implementation or not..is it optimum to optimizing the load on the db


2 - I used this query "SELECT [id], [name] FROM list WHERE (name like @SearchString + '%' ) and the search string is retrieved from a querystring which equals to the letter I want to order by But how can return all the names that start with numbers or other characters, I mean I don't want to list beside my alphabet list, a list of ALL the characters and numbers :S!

EDIT for point number 2!

I've managed to get the "Other" button to successfully filter all records that doesn't start with alphabet ( numers or special characters ) by using this Wildcards format name like '[^a-z]%' I hope it'll help other people!


3 - I've placed the repeater in the Page.aspx and then bound it to a SqlDataReader object instead of using a SqlDataSource in the code behind file, I thought it would be better to control opening and closing the connection and handle the errors as I one can't know what's going on with the connection while using SqlDataSource!, if I'm wrong please correct me, I just spent 1 month practicing! anyway when I first used SqlDataSource I could easily provide a default value for the parameter so I don't get an error because the display repeater needs to be populated and when first the page loads it's clean with no querystrings but I couldn't find a way now as i'm using some ADO.NET classes and as a datasource for the repeater a SqlDataReader Object

    <SelectParameters>
    <asp:QueryStringParameter Name="arrange_by_id" QueryStringField="ID" 
        Type="Int32" DefaultValue="1" />
    </SelectParameters>

P.S I thought about RegEx for filtering all the records that start with a number or character, it's like the sql wildcards but way more advances, problem is I don't know if it's even possible to be used in such situation or how to use it within my queries

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

ら栖息 2024-10-09 06:58:19

这是使用数据读取器的标准模式,我会使用它:

using (SqlConnection cn = new SqlConnection(connectionString))
{
  using (SqlCommand cm = new SqlCommand(commandString, cn))
  {
     using (SqlDataReader dr = cm.ExecuteReader();
     {
        // use dr to read values.
     }
  }
}        

Here is a standard pattern for using a datareader, I would use this:

using (SqlConnection cn = new SqlConnection(connectionString))
{
  using (SqlCommand cm = new SqlCommand(commandString, cn))
  {
     using (SqlDataReader dr = cm.ExecuteReader();
     {
        // use dr to read values.
     }
  }
}        
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文