How I convert this Vb.net to C#

Posted by Nuwan under ASP.NET on 8/10/2012 | Points: 10 | Views : 795 | Status : [Member] | Replies : 3
I got a code in vb.net for preparing user privileges, I want to convert to c#.
this is my code.

Public Shared Function GetMenueRights(ByVal mUsername As String, ByVal mTitle As String) As Boolean
Dim myConnection As SqlConnection = New SqlConnection(GetConnectionString)
Dim myCommand As SqlCommand
Dim myReader As SqlDataReader

myCommand = New SqlCommand("SELECT mr_user FROM MenuRights WHERE mr_user ='" & mUsername & "' AND mr_menutitle ='" & mTitle & "'", myConnection)
myConnection.Open()
myReader = myCommand.ExecuteReader
myReader.Read()
If myReader.HasRows = True Then
GetMenueRights = True
Else
GetMenueRights = False
End If
myConnection.Close()
End Function



Please help me.

Rathnayake


Responses

Posted by: Oswaldlily on: 8/10/2012 [Member] Starter | Points: 25

Up
0
Down

public static bool GetMenueRights(string mUsername, string mTitle)
{
bool functionReturnValue = false;
SqlConnection myConnection = new SqlConnection(GetConnectionString);
SqlCommand myCommand = default(SqlCommand);
SqlDataReader myReader = default(SqlDataReader);

myCommand = new SqlCommand("SELECT mr_user FROM MenuRights WHERE mr_user ='" + mUsername + "' AND mr_menutitle ='" + mTitle + "'", myConnection);
myConnection.Open();
myReader = myCommand.ExecuteReader;
myReader.Read();
if (myReader.HasRows == true) {
functionReturnValue = true;
} else {
functionReturnValue = false;
}
myConnection.Close();
return functionReturnValue;
}

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/10/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
Follow this url to convert ur vb.net code to c#
http://www.developerfusion.com/tools/convert/vb-to-csharp/

.

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ranjeet_8 on: 8/13/2012 [Member] [MVP] Gold | Points: 25

Up
0
Down
@Nuwan
Please Mark As Answer, if above post helps u.

Nuwan, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response