简体   繁体   中英

Issue with logging in application

I am trying to sort out the logging in app but some of the items I added to the code, get highlighted as an error. First of all, line 10, MySql is listed as an error, then line 32, 33, 34, 35 as well as 55.

Would you please assist me? Thanks

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using MySql.Data.MySqlClient; 

namespace WindowsFormsApplication3
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void label1_Click(object sender, EventArgs e)
        {

        }

        private void button1_Click(object sender, EventArgs e)
        {
            try

            {
                string myConnection = "datasource=s59.hekko.pl;port=3306;username=truex2_kuba;password=xxxx";
                SqlConnection myConn = new MySqlConnection(myConnection);
                MySqlCommand SelectCommand = new MySqlCommand("select * from databaase.users where uid='" + this.uid.Text + "' and pwd='" + this.pwd.Text + "' ;", myConn);
                MySqlDataReader myReader;
                myConnection.Open();
                myReader = SelectCommand.ExecuteReader();
                int count = 0;
                while (myReader())
                {
                    count = count + 1;
                }
                if (count == 1)
                {
                    MessageBox.Show("Nazwa uzytkownika i haslo sa poprawne");


                }
                else if (count > 1)
                {
                    MessageBox.Show("Wpisano zle dane uzytkownika");

                }
                else
                    MessageBox.Show("Wpisano zle dane uzytkownika");
                MyConn.Close();
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);

            }
        }
    }
}

You need to add MySql.Data reference to your project probably if line 10 fails. Afer that do following changes:

 SqlConnection myConn = new MySqlConnection(myConnection);

to

MySqlConnection myConn = new MySqlConnection(myConnection); 

then change

 myConnection.Open();

to

 myConn.Open();

then change

while (myReader())

to

 while (myReader.Read())

and finally

MyConn.Close();

to

 myConn.Close();

That should get you to go through build for start.

我在解决方案资源管理器中添加了MySql参考,这对您有所帮助。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM