Database search
-
I have a problem I'm busy writing a C#.NET project but walked into a problem. I've got a Form With 3 Textboxes a Button and a DataGrid. If i typ a value into the textboxes and i press the button. The datagrid Shows me the correct data. the Selectcommand: Select colom1, colum2, colom3, colom4, colom5 From Tabel1 Where (Colom1 = :param2) and (Colom2 = :param3) and (Colom3 = :param4) But now i want it like This: If i Typ a value for the first and last colom and nog the second one. I still want him te show me the data he found. If i do this now he says that he haven't got enough info to fill op my dataAdaptor. Wich is logic. But i realy don't have a clue how to do this.. can you help me?
-
I have a problem I'm busy writing a C#.NET project but walked into a problem. I've got a Form With 3 Textboxes a Button and a DataGrid. If i typ a value into the textboxes and i press the button. The datagrid Shows me the correct data. the Selectcommand: Select colom1, colum2, colom3, colom4, colom5 From Tabel1 Where (Colom1 = :param2) and (Colom2 = :param3) and (Colom3 = :param4) But now i want it like This: If i Typ a value for the first and last colom and nog the second one. I still want him te show me the data he found. If i do this now he says that he haven't got enough info to fill op my dataAdaptor. Wich is logic. But i realy don't have a clue how to do this.. can you help me?
Start using if statements to check which parameters to use in your SELECT query. something like:
StringBuilder sb = new StringBuilder();
sb.Append ("SELECT colom1, colum2, colom3, colom4, colom5 FROM Tabel1 ");
sb.Append ("WHERE ");
if (param2 != string.Empty)
sb.Append("(Colom1 = :param2)");
if (param3 != string.Empty)
sb.Append("(Colom2 = :param3)");
if (param4 != string.Empty)
sb.Append("(Colom3 = :param4)");or if this is in a stored procedure, make IF statements in your stored procedure.