2
I have a class, which is executed under a button, it makes two select
in a bank. apos, need to take these two data and make available to use in a second form, I’m trying to make EventHandler
, however, when running the system, it executes, but gives the error on the line: OnDataChange(info);
Error Object reference not set for an object instance
Follows code:
public void consulta()
{
string sqltring = @"Data Source=tptspo01sql01.database.windows.net;Initial Catalog=Tptecnologia;Integrated Security=False;User ID=********Password=*********@;Connect Timeout=60;Encrypt=False;TrustServerCertificate=False";
string _sql = string.Empty;
SqlConnection sqlcon = new SqlConnection(sqltring);
string usu, pass;
int eid, uid;
usu = textBox1.Text;
pass = textBox2.Text;
sqlcon.Open();
_sql = "SELECT Id_empresa FROM Login WHERE usuario = @usuario AND Passwd = @Passwd";
SqlCommand cmd = new SqlCommand(_sql, sqlcon);
cmd.Parameters.Add("@usuario", SqlDbType.VarChar).Value = usu;
cmd.Parameters.Add("@Passwd", SqlDbType.VarChar).Value = pass;
eid = (int)cmd.ExecuteScalar();
_sql = "SELECT Id_usu FROM Login WHERE usuario = @usuario AND Passwd = @Passwd";
SqlCommand cmd1 = new SqlCommand(_sql, sqlcon);
cmd1.Parameters.Add("@usuario", SqlDbType.VarChar).Value = usu;
cmd1.Parameters.Add("@Passwd", SqlDbType.VarChar).Value = pass;
uid = (int)cmd1.ExecuteScalar();
sqlcon.Close();
Hashtable info = new Hashtable();
info.Add("eid1", Convert.ToString(eid));
info.Add("uid1", Convert.ToString(uid));
OnDataChange(info);
Tinicial frm2 = new Tinicial();
frm2.Show();
}
In which line does the error occur? The number I saw, I need indication of what it is, since there is no.
– Maniero
Good night friend, after the line : info. Add("uid1", Convert.Tostring(uid));, where I call Ondatachange(info). in this line.
– Thomas Erich Pimentel
I can’t see a mistake there. I see a beautiful gambiarra, but it should work. At least this mistake, in this place, should not happen.
– Maniero