C sharp - No se Controlo NullReferenceEception

 
Vista:
sin imagen de perfil

No se Controlo NullReferenceEception

Publicado por elias (2 intervenciones) el 05/06/2015 17:47:37
hola buenas dias tengo un pequeño problema el cual necesito una pequeña ayuda con este programa que he creado el cual me genera este error despues de validar que el texbox no este en blanco le anexo el codigo y en donde me genera el error

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
}
	OleDbConnection cone = new OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source=Base de datos Aplicativo Energia.accdb;Persist Security Info=False ");
	OleDbCommand comand = new OleDbCommand();
	OleDbDataReader recuperar;
	private void button1_Click(object sender, EventArgs e)
	{
		if (textBox1.Text != "" & textBox2.Text != "")
		{
			cone.Open();
			comand = new OleDbCommand(" select * from Usuario where Usuarios = '" + textBox1.Text + "' and Clave = '" + textBox2.Text + "'", cone);
			recuperar = comand.ExecuteReader();
 
		}
 
		else
		{
			MessageBox.Show("No puede ir vacio debe Suministrar los Campo Solicitados");
		}
 
		if (recuperar.Read())     aqui me genera el error de ExepcionNullrefence referencia a objeto no establecida como instancia de un objeto
		{
			MessageBox.Show("BIENVENIDO A SICENE");
			Form2 ventana = new Form2();
			ventana.ShowDialog();
			textBox1.Text = "";
			textBox2.Text = "";
		}
		else
			MessageBox.Show("usuario o clave errada");
		textBox1.Text = "";
		textBox2.Text = "";
		cone.Close();
		this.Close();

ayudenme por favor y de antemano gracias
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
sin imagen de perfil

No se Controlo NullReferenceEception

Publicado por David (60 intervenciones) el 10/06/2015 15:37:34
¿La línea
1
comand = new OleDbCommand(" select * from Usuario where Usuarios = '" + textBox1.Text + "' and Clave = '" + textBox2.Text + "'", cone);

no te da error de compilación?

Debería ser:
1
comand = new OleDbCommand(" select * from Usuario where Usuarios = '" + textBox1.Text + "' and Clave = '" + textBox2.Text + "'", cone as OleDbConnection);

Si así tampoco te funciona, seguramente cone sea null.
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