ahmedaziz
Well-known member
- Joined
- Feb 22, 2023
- Messages
- 55
- Programming Experience
- 1-3
I work on some ui web tool on asp.net core blazor
i need to write csharp function convert this conditions to sql statement so
when i filter two columns as databasename and remarks
so csharp function will convert text received to sql statement
so csharp function will return string and it will take only one parameters text
as
and it will return
I need to do it with dynamic way so may be it have one column filter may be 2 columns or 3 column filter
then convert it to sql statement
what i try but not give me exact result i need
i need to write csharp function convert this conditions to sql statement so
when i filter two columns as databasename and remarks
C#:
(databaseName == null ? "" : databaseName).ToLower().Contains("db_".ToLower()) and (remarks == null ? "" : remarks).ToLower().Contains("adc".ToLower())
C#:
databaseName like '%db_%' and Remarks like '%adc%'
as
C#:
(databaseName == null ? "" : databaseName).ToLower().Contains("db_".ToLower()) and (remarks == null ? "" : remarks).ToLower().Contains("adc".ToLower())
C#:
databaseName like '%db_%' and Remarks like '%adc%'
I need to do it with dynamic way so may be it have one column filter may be 2 columns or 3 column filter
then convert it to sql statement
what i try but not give me exact result i need
what i try but not give me result i need:
{
var pairs = new List<string>();
string[] substrings = input.Split(new[] { "Contains(" }, StringSplitOptions.None);
foreach (string substring in substrings)
{
int index = substring.IndexOf(".ToLower()");
if (index != -1)
{
string key = substring.Substring(0, index).Trim().Split(' ')[0];
string value = substring.Substring(index + ".ToLower()".Length).Trim().TrimEnd(')');
pairs.Add($"{key} like '{value}'");
}
}
return string.Join(" and ", pairs);
}