Can some one help me convert this to 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
}
}
you can use this converter for future conversions.
EDIT:
you’ll have to wire up the event in c# like this