Advertisement
Guest User

Untitled

a guest
Apr 25th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.55 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Threading.Tasks;
  9. using System.Windows.Forms;
  10. using MySql.Data.MySqlClient;
  11.  
  12. namespace SampleProject
  13. {
  14. public partial class Form1 : Form
  15. {
  16. public Form1()
  17. {
  18. InitializeComponent();
  19. }
  20.  
  21.  
  22. private void btnlogin_Click(object sender, EventArgs e)
  23. {
  24. string ConnectionString = "Server=localhost;Database=test;Uid=root;Pwd=password;sslmode=none;";
  25. using (MySqlConnection con = new MySqlConnection(ConnectionString))
  26. {
  27. con.Open();
  28. using (MySqlCommand cmd = con.CreateCommand())
  29. {
  30. cmd.CommandText = @"select count(*) from mysqlcsharp where UserName=@UserName and Password=@Password";
  31. cmd.Parameters.Add(new MySqlParameter("UserName", txtuser.Text));
  32. cmd.Parameters.Add(new MySqlParameter("Password", txtpass.Text));
  33. int i = Convert.ToInt32(cmd.ExecuteScalar());
  34. if (i > 0)
  35. {
  36. MessageBox.Show("UserName and Password correct.", "Succes!",MessageBoxButtons.OKCancel,MessageBoxIcon.Information);
  37. }
  38. else
  39. {
  40. MessageBox.Show("UserName or Password error.");
  41. }
  42. }
  43. }
  44. }
  45. }
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement