Click to See Complete Forum and Search --> : Database result not returning:


mbewers980
06-12-2009, 05:09 AM
Good morning

This method was definitely working for me before and I can't seem to find out what I've changed that makes it return the following error when running my application now:

public DataTable SearchDefault(string searchItem, string criteria)
{
using (OracleConnection oce = new OracleConnection(ConnectionString))
{
oce.Open();
DataTable ds = new DataTable();

OracleCommand command = oce.CreateCommand();
command.CommandType = CommandType.Text;
string queryString =
string.Format(@"SELECT corporateactionnumber, sedolnumber,
isincode, stockname, corporateactiontype, receiveddate, admincode,
signedoff, effectivedate, paymentdate, agentdeadlinedate, customerdeadline,
ratio1, ccy, price, newname, terms, diarynotes
FROM tblcorporateactions
WHERE {0} = {1}", searchItem, criteria);
command.CommandText = queryString;

command.Prepare();
OracleDataAdapter productsAdapter = new OracleDataAdapter(command);
productsAdapter.Fill(ds);
return ds;
}

As you can see, I'm passing in 2 statements to the where clause in my select statement but, every time this method is run, nothing is returned and my program throws an exception.

When I changed the Exception type in my try/catch clause of thw eeb page which is calling this method, I got an: 'Oracle Error: Unable to cast object of type' message, but yet I'm not trying to cast anything, I'm simple returning a table of results.

Any help would be appreciated!

Thanks
Matt

mbewers980
06-12-2009, 08:16 AM
Please, if someone is viewing this, can they relpy? I have had 41 viewings and no replies!!

chazzy
06-12-2009, 06:10 PM
yes you are.

when you do this:


SELECT corporateactionnumber, sedolnumber,
isincode, stockname, corporateactiontype, receiveddate, admincode,
signedoff, effectivedate, paymentdate, agentdeadlinedate, customerdeadline,
ratio1, ccy, price, newname, terms, diarynotes
FROM tblcorporateactions
WHERE {0} = {1}


assuming that searchItem is one of the columns in the table (say, sedolnumber) and the criteria is bob, then your query is invalid. you should wrap the second input w/ '' or use actual bind parameters.

sayfrndship1234
07-02-2009, 11:51 PM
why are u trying to use query in complex mode. just use query in simple string format, and pass ur parameter to it.according to field in your table.

mbewers980
07-03-2009, 03:09 AM
It's okay. I've got this sorted now.

Thanks for your help.