我有YearField,它是我数据库中的字符串。我想编写一个函数,以允许用户能够使用Between搜索YearField。
`Public Function DoubleQuote(strInput As String, intElement As Integer) As String
Dim a() As String
Dim b() As String
Dim i As Integer
ReDim b(0)
a = Split(strInput, Chr(34))
' ***** See comments re using -1 *******
For i = 0 To UBound(a) - 1
If Len(a(i)) = 0 Then
b(UBound(b)) = Chr(34) & a(i + 1) & Chr(34)
i = i + 1
Else
b(UBound(b)) = a(i)
End If
ReDim Preserve b(UBound(b) + 1)
Next i
DoubleQuote = b(intElement)
End Function`
我在动态linq行中遇到以下错误。
没有适用的方法' ToInt32'存在于'转换'
中我也用以下内容替换searchQuery,但是没有工作,出现了同样的错误。
string fromYear = tbxFromYear.Text;
string toYear = tbxToYear.Text;
searchQuery = "Convert.ToInt32(YearField) > (@0) && Convert.ToInt32(YearField) < (@1)";
var result = db.selectDataFromSharedView().AsQueryable().
Where(searchQuery, Convert.ToInt32(fromYear),Convert.ToInt32(ToYear)).OrderBy("YearField Descending").ToList();
答案 0 :(得分:0)
你能试试吗?
int fromYear = Convert.ToInt32(tbxFromYear.Text);
int toYear = Convert.ToInt32(tbxToYear.Text);
var values = new[] {fromYear, toYear };
searchQuery = "Convert.ToInt32(YearField) > @0 AND Convert.ToInt32(YearField) < @1";
var result = db.selectDataFromSharedView().AsQueryable()
.Where(searchQuery, values )
.OrderBy("YearField Descending")
.ToList();