mysql - Login Authentication to Database using C# -
newly, i'm working xamarin studio build program using c#. know quite simple question, can't it. want know kind of code have use authenticate login mysql database. thanks
using system; using system.data; using mysql.data.mysqlclient; using gtk; public partial class mainwindow: gtk.window { public mainwindow () : base ("repsys icdx 1.0 - login") { setdefaultsize (282, 142); setposition (windowposition.center); deleteevent += ondeleteevent; label uid = new label ("username\t: "); label pass = new label ("password\t: "); entry uide = new entry(); entry passe = new entry (); passe.visibility = false; button login = new button ("log-in"); button exit = new button (stock.cancel); login.setsizerequest (75, 30); exit.setsizerequest (75, 30); fixed fix = new fixed (); fix.put (uid, 20, 30); fix.put (pass, 20, 60); fix.put (uide, 100, 26); fix.put (passe, 100, 56); fix.put (login, 101, 90); fix.put (exit, 186, 90); add (fix); showall (); login.clicked += delegate { //what should here authenticate user login??? }; exit.clicked += delegate { application.quit(); }; } private void ondeleteevent (object sender, deleteeventargs a) { application.quit (); a.retval = true; } }
see this tutorial. example done visual studio, should no problem ide.
your click handler needs modified:
login.clicked += delegate { mysqlconnection connection = new mysqlconnection("server=localhost;database=testdb;uid=<your user>;pwd=<your password>"); mysqlcommand command = connection.createcommand(); command.commandtext = "select * table;" mysqldatareader reader = command.executereader(); while (reader.read()) { console.writeline(string.format("{0}", reader[0])); } reader.close(); command.close(); connection.close(); }; do not forget add using declaration:
using: mysql.data.mysqlclient; you need add mysql.dll (win apps) , mysql.web.dll (web apps) references.
Comments
Post a Comment