Ver Mensaje Individual
  #1 (permalink)  
Antiguo 10/10/2010, 10:45
juliancho1989
 
Fecha de Ingreso: octubre-2010
Ubicación: Bucaramanga
Mensajes: 7
Antigüedad: 13 años, 6 meses
Puntos: 0
Execute reader en C#

Resulta que estoy haciendo un formulario de validacion de entrada con nombre de usuario, el cual usa el email, y la contraseña. Pero me sale el error de que en el Excecutereader.

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '='[email protected]' and contrasena='123'' at line 1

Este error en tiempo de ejecucion.

Aqui esta el codigo completo.

Espero alguein me pueda ayudar


using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;
using MySql.Data;
using System.Data.Sql;
using System.Data.SqlClient;


namespace prueba
{



public partial class frmlogin : Form
{
MySqlConnection cn;
string str;
MySqlCommand command;
MySqlDataReader dr;
string usu;
int filas;


public frmlogin()
{
InitializeComponent();
}

private void btnLogin_Click(object sender, EventArgs e)
{
if (verificaUsuario(this.txtUsuario.Text, this.txtContra.Text))
{
if (filas ==1)
{
MessageBox.Show("Bienvenido " + usu + " ","Acceso al sistema", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1);
}
else
{
MessageBox.Show("Datos incorrectos","Acceso al sistema",MessageBoxButtons.OK,MessageBoxIcon.Error ,MessageBoxDefaultButton.Button1);
}
}

}

private bool verificaUsuario(string usuario, string pass)
{
string myUser = usuario.Trim();

str = ("Server=localhost;Database=socrates;User id=root;Password=12345");
cn = new MySqlConnection();
cn.ConnectionString = str;
System.Text.StringBuilder sel = new System.Text.StringBuilder();
sel.Append("Select *from usuario");
sel.Append("where email_usuario=@USUARIO and contrasena=@PASS");
command = new MySqlCommand(sel.ToString(), cn);
command.Parameters.Add("@USUARIO", MySqlDbType.VarChar, 50);
command.Parameters.Add("@PASS", MySqlDbType.VarChar, 50);
command.Parameters["@USUARIO"].Value = myUser;
command.Parameters["@PASS"].Value = pass;
cn.Open();
dr = command.ExecuteReader();
filas = Convert.ToInt32(dr.HasRows); //obtiene las filas de la consulta
if (dr.Read())
{
usu = Convert.ToString(dr[1]);
}
cn.Close();
dr.Close();
return true;
}

private void frmlogin_Load(object sender, EventArgs e)
{

}
}
}