Quantcast
Channel: MySQL Forums - Connector/NET and C#, Mono, .Net
Viewing all articles
Browse latest Browse all 1447

ERROR AL CONECTAR C# VISUAL STUDIO Y MYSQL (no replies)

$
0
0
CHICOS EL SIGUIENTE CÓDIGO ES DE UN TUTORIAL REALIZADO EN SQLSERVER, LO QUE HICE FUE PASAR LAS SENTENCIAS SQLSERVER A MYSQL. PERO CUANDO LO COMPILO ME SALE EL ERRRO.



Es en tres capas.

Capa_Conexion datos

Clase. Conexion_Data

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;

}
}
}
Clase consul_user

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;
}
}
}

CAPA_COMERCIO

Clase Conexion_User

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;
}
}
}


Capa_formularios

Codifo evento click. de boton

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(); //(X) EXEPCION NO CONTROLADA // ***//
if (LogUser.Read() == true)
{
this.Hide();
menuform fmrPrr = new menuform();
fmrPrr.Show();

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

//**// EXCEPCIÒN NO CONTROLADA.

MySql.Data.MySqlClient.MySqlExcepcion:' You have an erro in your SQL Sintax; check the manual that corresponds to your MySql server version for the rigth sintaxis to usear near' Formulario where name_user= ADMINSYS AND PASS_user=1234567' at line 1.

ese es el mensaje cuando se compila el codigo en Visual Studio.

Viewing all articles
Browse latest Browse all 1447

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>