C sharp - tengo un ERROR

 
Vista:

tengo un ERROR

Publicado por ileana (17 intervenciones) el 27/09/2005 05:03:14
Estoy con el mismo mensaje de abajo por yamil lo cambie y cree esta conexion pero ahora me da este
OdbcDataAdapter dv = new OdbcDataAdapter();
string conexion = "Select count (*) from pla_usuarios WHERE usuario = '"+this.textBox1.Text+"' AND clave ='"+this.textBox2.Text+"'";
DataTable dt = new DataTable();
dv.Fill(dt);
if(Convert.ToInt32(dt.Rows[0][0])>0)
{
MessageBox.Show("Usuario y Contrasena correctos");
}
else
{
MessageBox.Show("Usuario y Contrasena incorrectos");
}

pero ahora me da este error

An unhandled exception of type 'System.InvalidOperationException' occurred in system.data.dll

Additional information: The SelectCommand property has not been initialized before calling 'Fill'.
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder

RE:tengo un ERROR

Publicado por Edgar (278 intervenciones) el 27/09/2005 18:05:22
Hola

No has asignado el select.. hazlo asi

string conexion = "Select count (*) from pla_usuarios WHERE usuario = '"+this.textBox1.Text+"' AND clave ='"+this.textBox2.Text+"'";
OdbcDataAdapter dv = new OdbcDataAdapter(conexion);

Saludos
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
sin imagen de perfil
Val: 158
Bronce
Ha disminuido 1 puesto en C sharp (en relación al último mes)
Gráfica de C sharp

RE:tengo un ERROR

Publicado por Yamil Bracho (1164 intervenciones) el 27/09/2005 19:05:57
Si te interesa saber si el usuario existe es mas facil usar el metodo ExecuteScalar. Asi te quedaria:

String sql = "Select count (*) from pla_usuarios WHERE usuario = '"+this.textBox1.Text+"' AND clave ='"+this.textBox2.Text+"'";
SqlCommand orders cmd = new SqlCommand( sql, conn);

Int32 count = (Int32) cmd.ExecuteScalar();
if ( count == 0 )
{
// no existe
}
else
{
// Si existe
}
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar