Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Converting VB to C#
Message
General information
Forum:
ASP.NET
Category:
Other
Miscellaneous
Thread ID:
00733240
Message ID:
00733301
Views:
19
Here is taking Paul's code and converting it to C#:
public string  Search( string  a) 
{

	System.Text.StringBuilder sbSQL = new System.Text.StringBuilder();
	sbSQL.Append("SELECT * FROM Articles WHERE");

	foreach ( string words in a.Split(' '))
	{
		if ( words.Trim().Length > 0 ) 
		{
			sbSQL.Append(@" ArticleTitle LIKE %");
			sbSQL.Append(words + @"% OR ArticleKeywords LIKE %");
			sbSQL.Append(words + @"% AND");
		}
	}

        string  SQL;
        SQL = sbSQL.ToString();
        SQL = SQL.Substring(0, SQL.Length - 5);

        return SQL;
}
>>Hi all,
>>
>>Can any one offer some assistances in converting ASP(VB) to ASP.NET(C#).
>>
>>I have a function that I would use when doing a "search" in ASP(VB) but like most I am trying to make the leap from ASP to ASP.NET.
>>
>>Any help in converting the below function would be greatly appreciated.
>>
>
>Something like this should work:
>
>
>Public Function Search(ByVal a As String) As String
>
>        Dim sbSQL As System.Text.StringBuilder = New System.Text.StringBuilder()
>        sbSQL.Append("SELECT * FROM Articles WHERE")
>        Dim words As String
>
>        For Each words In a.Split(" ")
>            If words.Trim().Length > 0 Then
>                sbSQL.Append(" ArticleTitle LIKE '%")
>                sbSQL.Append(words + "%' OR ArticleKeywords LIKE '%")
>                sbSQL.Append(words + "%' AND")
>            End If
>        Next
>
>        Dim SQL As String
>        SQL = sbSQL.ToString()
>        SQL = SQL.Substring(0, SQL.Length - 5)
>
>        Return SQL
>    End Function
>
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform