C
C#13mo ago
breack

i need help because i dont why this is null

if u need smt (sql or smt ab my visual code lmk please)
No description
28 Replies
Scratch
Scratch13mo ago
I don't know what listar is but it's returning null ToList?
breack
breackOP13mo ago
1 second it supposed to find the user that I have already created in SQL
breack
breackOP13mo ago
No description
breack
breackOP13mo ago
No description
breack
breackOP13mo ago
so the Documento is Document It should be "161616" and contraseña is password it should be "123" but for some reason he can't find it
Scratch
Scratch13mo ago
is listar() your own function?
breack
breackOP13mo ago
yes
Scratch
Scratch13mo ago
show the code for that
breack
breackOP13mo ago
the code is in spanish because english is no my main language so I'm sorry for not knowing how to ask very well but it's really difficult to ask something in a language you don't understand 1 second using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Data; using System.Data.SqlClient; using Entidad; namespace Datos { public class D_Usuario { public List<Usuario> listar () { List<Usuario> lista = new List <Usuario>(); using (SqlConnection oconexion = new SqlConnection(Conexion.cadena)) { try { string query = "Select Id_usuario,Documento,Nombre_Completo,correo,Clave,Estado from usuario"; SqlCommand cmd = new SqlCommand(query, oconexion); cmd.CommandType = CommandType.Text; oconexion.Open(); using (SqlDataReader dr = cmd.ExecuteReader()) { while(dr.Read()) { lista.Add(new Usuario() { Id_usuario = Convert.ToInt32(dr["Id_usuario"]), Documento = dr["Documento"].ToString(), Nombre_Completo = dr["Nombre_Completo"].ToString(), correo = dr["correo"].ToString(), Clave =dr["clave"].ToString(), Estado = Convert.ToBoolean(dr["Estado"]) }); } } } catch (Exception ex) { lista = new List<Usuario>(); } } return lista; } } } the program is supposed to work with the sql database
Scratch
Scratch13mo ago
oh which line did you break on? It looks like line 29, which is before that code's executed
breack
breackOP13mo ago
The code is made in capes so it is a little difficult i got 4 capes im gonna show u the conecction cape
breack
breackOP13mo ago
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms; using Negocio; using Entidad; namespace ProyectoBD { public partial class Login : Form { public Login() { InitializeComponent(); } private void btnCancelar_Click(object sender, EventArgs e) { this.Close(); } private void btnIngresar_Click(object sender, EventArgs e) { List<Usuario> PRUEBA = new N_Usuario().listar(); Usuario osuario = new N_Usuario().listar().Where(u => u.Documento == txtdocumento.Text && u.Clave == txtclave.Text).FirstOrDefault(); if(osuario != null ) { Inicio form = new Inicio(); form.Show(); this.Hide(); form.FormClosing += Frm_closing; }else { MessageBox.Show("No se encontre el usuario","Mensaje",MessageBoxButtons.OK,MessageBoxIcon.Exclamation); } } private void Frm_closing(object sender , FormClosingEventArgs e) { txtdocumento.Text = ""; txtclave.Text = ""; this.Show(); } } }
breack
breackOP13mo ago
this is the full code of that picture sure
Scratch
Scratch13mo ago
I need to see that red/yellow icon that's cut off
Scratch
Scratch13mo ago
set the breakpoint on line 32 instead, and hit that
breack
breackOP13mo ago
i did put the problem is the program doesnt recognize the data base i think
Scratch
Scratch13mo ago
great what's the error when that happens
breack
breackOP13mo ago
because the idea is u can login with this user but when you try to put that it comes out null (so it doesn't recognize it) I guess there must be something wrong in the "Where" but I don't know what it is and thats what im asking why when u put this user and this password says "null"
Scratch
Scratch13mo ago
oh I see remove the try/catch here then your program will crash with the real error message
breack
breackOP13mo ago
sure im little confuse idk if u can just send me that i need to remove
breack
breackOP13mo ago
breack
breackOP13mo ago
but idk what i did wrong
Scratch
Scratch13mo ago
remove the try/catch and the catch statement. I won't give you the exact code because then you don't learn anything
breack
breackOP13mo ago
Scratch
Scratch13mo ago
yes, that's the error you need to solve
Want results from more Discord servers?
Add your server