I have a class, which is executed under a button, it makes two select
in a bank. I am trying to do this with EventHandler
, however, when running the system, it executes, but gives the error in the line: OnDataChange(info);
Error Object reference not set to an instance of an object
Followthecodebelow:
publicvoidconsulta(){stringsqltring=@"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();
}