나는 다음과 같은 것은 행 필터의 RowFilter LIKE 작동
'캐나다 %이 .txt'또는 '캐나다 * .txt 인'
로 허가되어 있지 않은 것을 알고 내가
로 내 필터를 다시 작성할 수 있습니다 추측file_name like 'Canada%' and file_name like '%.txt'
해야합니다.
그러나 %가 어디에 있고 문자열을 분할하는 대신에 더 쉬운 방법이 있습니까?
나는 다음과 같은 것은 행 필터의 RowFilter LIKE 작동
'캐나다 %이 .txt'또는 '캐나다 * .txt 인'
로 허가되어 있지 않은 것을 알고 내가
로 내 필터를 다시 작성할 수 있습니다 추측file_name like 'Canada%' and file_name like '%.txt'
해야합니다.
그러나 %가 어디에 있고 문자열을 분할하는 대신에 더 쉬운 방법이 있습니까?
CHARINDEX가 필터 식에 허용되지 않는다고 생각합니다.
당신은 동적으로 C#을에서 필터 문자열을 빌드 할 수 있습니다 (여기, 아주 많이 안된하지만이있어 가능한 구문) : 여기
//split the original string using the wildcard as the delimiter
string[] f = s.Split('%');
//use the resulting array to build the resultstring
string resultstring = 'file_name like "' + f[0] + '%" and file_name like "%' + f[1] + '"'
//view.RowFilter = resultstring;
내가
private string CreateRowFilter(string remoteFilePattern)
{
string[] pattern = remoteFilePattern.Split(new char[] { '*', '%' });
int length = pattern.GetUpperBound(0);
if (length == 0)
{
return String.Format("Name = '{0}'", pattern[0]);
}
StringBuilder fileter = new StringBuilder(
String.Format("Name LIKE '{0}*' ", pattern[0]));
for (int segment = 1; segment < length; segment++)
{
fileter.Append(
String.Format("AND Name LIKE '*{0}*' ", pattern[segment]));
}
if(String.IsNullOrEmpty(pattern[length]) == false)
{
fileter.Append(
String.Format("AND Name LIKE '*{0}' ", pattern[length]));
}
return fileter.ToString();
}
I와 함께 제공되는 솔루션입니다 거기에 몇 가지 따옴표를 벗어나는 것을 잊어 버린 것 같지만 잘하면 당신은 아이디어를 얻고 ... 잘하면 그것은 당신을 위해 작동합니다 ... – LesterDove
이것은 * 또는 %로 분할하고 다시 작성하는 기능으로 지금하고 있습니다. 나는 테이블에 적용 할 수있는 멋진 linq 함수가 있는지 궁금해했다. – Mike