帮助转换为C#

G G*_* Gr -1 c# asp.net .net-3.5 c#-4.0

有人可以帮我转换成c#吗?

   //' Import the ODBC namespace for MySQL Connection  
   Imports System.Data.Odbc  
   Partial Class login  
       Inherits System.Web.UI.Page  

       Protected Sub Login1_Authenticate(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.AuthenticateEventArgs) Handles Login1.Authenticate  
           Dim cn As New OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mydb; User=root;Password=;")  
           cn.Open()  
           Dim cmd As New OdbcCommand("Select * from login where username=? and password=?", cn)  

           //'Add parameters to get the username and password  

           cmd.Parameters.Add("@username", OdbcType.VarChar)  
           cmd.Parameters("@username").Value = Me.Login1.UserName  

           cmd.Parameters.Add("@password", OdbcType.VarChar)  
           cmd.Parameters("@password").Value = Me.Login1.Password  

           Dim dr As OdbcDataReader  
           //' Initialise a reader to read the rows from the login table.  
           //' If row exists, the login is successful  

           dr = cmd.ExecuteReader  

           If dr.HasRows Then  
               e.Authenticated = True  
               //' Event Authenticate is true  
           End If  

       End Sub  
   End Class  
    }
} 
Run Code Online (Sandbox Code Playgroud)

Bal*_*a R 5

// Import the ODBC namespace for MySQL Connection  
using System.Data.Odbc;
partial class login : System.Web.UI.Page
{



    protected void  
Login1_Authenticate(object sender, System.Web.UI.WebControls.AuthenticateEventArgs e)
    {
        OdbcConnection cn = new OdbcConnection("Driver={MySQL ODBC 3.51 Driver};Server=localhost;Database=mydb; User=root;Password=;");
        cn.Open();
        OdbcCommand cmd = new OdbcCommand("Select * from login where username=? and password=?", cn);

        //Add parameters to get the username and password  

        cmd.Parameters.Add("@username", OdbcType.VarChar);
        cmd.Parameters["@username"].Value = this.Login1.UserName;

        cmd.Parameters.Add("@password", OdbcType.VarChar);
        cmd.Parameters["@password"].Value = this.Login1.Password;

        OdbcDataReader dr = default(OdbcDataReader);
        // Initialise a reader to read the rows from the login table.  
        // If row exists, the login is successful  

        dr = cmd.ExecuteReader();

        if (dr.HasRows) {
            e.Authenticated = true;
            // Event Authenticate is true  
        }

    }
}
Run Code Online (Sandbox Code Playgroud)

您可以将此转换器用于将来的转换.

编辑:

你必须像这样在c#中连接事件

protected void Page_Load(object sender, EventArgs e)
{
       Login1.Authenticate += Login1_Authenticate; 
}
Run Code Online (Sandbox Code Playgroud)

  • 现在我们有人类代理Web服务.我想知道他是否支持NTLM?;) (2认同)