Click here to Skip to main content
15,897,187 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have a code in vb.net and i am converting it into c# using online conversion tool but there is a error while converting it into c#. my vb.net code is -

VB
Private Sub Page_Init(ByVal sender as System.Object, ByVal e as System.EventArgs) 'Handles MyBase.Init
 If Page.Session("auth_EmployeeID") <> Convert.ToInt32(Page.User.Identity.Name) Then Call Reset_Session_Data(Page)
    End Sub

after converting the c# code is -
C#
private void Page_Init(System.Object sender, System.EventArgs e) //Handles MyBase.Init
    {
        if (Page.Session["auth_EmployeeID"] != Convert.ToInt32(Page.User.Identity.Name))
        {
            Reset_Session_Data(Page);
        }
    }


Here is the error -
the best overloaded method match for cntrl_lib_nav.Reset.Session.Data(ref System.Web.UI.Page) has some invalid arguments.


here is the function :

C#
public static void Reset_Session_Data(ref Page refPage)
  {
      SqlConnection conn = new SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);
      SqlCommand command = new SqlCommand("sproc_CP_EmployeeGet", conn);
      command.CommandType = CommandType.StoredProcedure;

      SqlParameter param = command.Parameters.Add("@EmployeeID", SqlDbType.Int);
      param.Value = Convert.ToInt32(refPage.User.Identity.Name);

      conn.Open();
      SqlDataReader rs = command.ExecuteReader();

      if (!rs.Read())
          refPage.Response.Redirect("login.aspx");

      refPage.Session["auth_EmployeeID"] = rs["EmployeeID"];
      refPage.Session["Name"] = rs["first_name"] + " " + rs["last_name"];
      refPage.Session["user_default_office"] = rs["officeID"];
      refPage.Session["user_groups"] = Strings.Replace(rs["security_group_list"], ",", "~");
      if (Strings.InStr(refPage.Session["user_groups"], "~1~") > 0)
      {
          refPage.Session["is_admin"] = true;
          refPage.Session["user_default_office"] = "all";
      }

      rs.Close();
      rs = null;
      command = null;
  }
Posted
Updated 25-May-15 2:09am
v2
Comments
Maciej Los 25-May-15 8:17am    
Are you an author of the same question on SO: http://stackoverflow.com/questions/30432263/conversion-of-vb-net-to-c-sharp ?
Maciej Los 25-May-15 8:18am    
We need original code of Reset_Session_Data function/method in vb.net.

Change

Reset_Session_Data(Page);


to

Reset_Session_Data(ref Page);


or change

public static void Reset_Session_Data(ref Page refPage)


to

public static void Reset_Session_Data(Page refPage)
 
Share this answer
 
You can always translate code (not "convert"!) automatically. Please see my past answer:
Code Interpretation, C# to VB.NET[^].

Most reliable and quality method is using open-source ILSpy.

—SA
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900