I have following code:
In a Form:
public void filterType_TextChanged(object sender, EventArgs e)
{
var dSearch = new D_Search(this);
dSearch.filterD(sender);
}
So I have a Textbox event where I call a filterD function in another class dSearch. In the class dSearch I have:
public D_Search(Form1 frm1)
{
form1 = frm1;
}
public String filterD(object sender)
{
string val = String.Empty;
if (sender == form1.filterType())
{
val = (sender as TextBox).Text;
//havent written the whole SQL Command here
sqlCmd = new SqlCommand("SELECT * FROM, connection);
}
datTable = new DataTable();
sqlDatAdapter = new SqlDataAdapter(sqlCmd.CommandText,
connection); //causes NullReferenceException
sqlDatAdapter.Fill(datTable);
form1.setDataGrid = datTable;
return val;
}
So I have multiple functions in my Form like filterType which are Textbox events. Now I want to pass them to my Class which should notice with if-statement what event was called (what Textbox was changed) but I get a NullReference Exception at sqlDatAdapter. What should I do?
EDIT: It's the cmd that is null. Additionally:
Here is the filterType function:
public String filterType()
{
return filterTypeNumber.Text;
}
EDIT2: The if statement is not used, so he does not recognize the sender, because he compares if the sender is the Textbox entry. What should I do?