WebMatrix中的sql LIKE% [英] WebMatrix sql LIKE %

查看:156
本文介绍了WebMatrix中的sql LIKE%的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下查询的麻烦。它的工作原理,当我与静态参数直接执行它WebMatrix中,并返回一个几行,但不能从我的.cshtml页

I am having trouble with the following query. It works when I execute it directly from WebMatrix with static parameters and returns a few rows, but not from my .cshtml page

var accounts = database.Query(
  @"SELECT Username, Email, row_count
  FROM (SELECT Username, Email, Count(0) OVER() as row_count, ROW_NUMBER() OVER(ORDER BY @0 DESC) as row_number 
  FROM UserProfile 
  WHERE Username LIKE %@1% AND Email LIKE %@2%) as accounts
  WHERE row_number BETWEEN @3 AND @4",
  new object[] { sort, username, email, start, end });

当我更换一些参数,如@ 1和@ 2它的工作原理静态值,但是它没有ORDER BY参数@ 0

When I replace the LIKE parameters @1 and @2 with static values it works, but it does not ORDER BY parameter @0

推荐答案

在你的SQL中使用这样的:

Use this in your sql:

LIKE '%' + @1 + '%'

这篇关于WebMatrix中的sql LIKE%的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆