MySQL Forums
Forum List  »  Spanish

ERROR AL CONECTAR C# VISUAL STUDIO Y MYSQL
Posted by: Luis Hernando Rojas Rojas
Date: November 06, 2018 01:35PM

Buenas tardes chicos tengo el siguiente error al crear un login, el código es de un tutorial echo en sqlserver, pero pase los parámetros a Mysql.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data.MySqlClient;

namespace Capa_Datos
{
class Conexion_data
{
private MySqlConnection conect = new MySqlConnection("Server=localhost;Database=cont_data;Uid=root;Pwd=Lhr310528;");
public MySqlConnection openconect()
{
if (conect.State == ConnectionState.Closed)
conect.Open();
return conect;
}

public MySqlConnection closconect()
{
if (conect.State == ConnectionState.Open)
conect.Close();
return conect;

}
}
}


using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Data;
using MySql.Data.MySqlClient;

namespace Capa_Datos
{
public class Consult_User
{
private Conexion_data conect = new Conexion_data();
private MySqlDataReader read;

public MySqlDataReader ConsultUser(string user, string password)
{
string qry = "Select * from long_cont where name_user='" + user + "' and pass_user='" + password+"'";
MySqlCommand command = new MySqlCommand();
command.Connection = conect.openconect();
command.CommandText = qry;
read = command.ExecuteReader();

return read;
}
}
}

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using MySql.Data.MySqlClient;
using MySql.Data;
using Capa_Datos;

namespace Capa_Negocios
{
public class Conexion_User
{

private Consult_User DateUSer = new Consult_User();

//Variables
private string _user;
private string _password;
// Sepuede Agregar las Necesarias para validar el correcto acceso al sistema

public String SysUser
{
set { _user = value; }
get { return _user; }
}

public String Syspassword
{
set { _password = value; }
get { return _password; }
}

//COnstructor
public Conexion_User() { }

//Funcion Metodos

public MySqlDataReader Logsys()
{
MySqlDataReader LogUser;
LogUser = DateUSer.ConsultUser(SysUser, Syspassword);
return LogUser;
}
}
}



private void btn_log_Click(object sender, EventArgs e)
{
Conexion_User acceso = new Conexion_User();
MySqlDataReader LogUser;
acceso.SysUser = txt_user.Text;
acceso.Syspassword = txt_pass.Text;
LogUser = acceso.Logsys();
if (LogUser.Read() == true)
{
this.Hide();
menuform fmrPrr = new menuform();
fmrPrr.Show();

}
else
MessageBox.Show("Usuarios Invalidos");
}





Tengo bien las referencias pero me sale el siguiente error al compilar.

Options: ReplyQuote


Subject
Views
Written By
Posted
ERROR AL CONECTAR C# VISUAL STUDIO Y MYSQL
198
November 06, 2018 01:35PM


Sorry, only registered users may post in this forum.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.