August 29, 2006 at 11:11 am
I wrote this method:
public
DataSet selectItems_by_Location(String location)
{
SqlDataAdapter cmdItemTypes = new SqlDataAdapter("Select ItemName,ItemModel,PurchaseDate,Location,DepartureDate,ItemType,AdditionalInfo From Items Where Location = " + location + "", con);
con.Open();
try
{
cmdItemTypes.Fill(dSet,
"ItemsByLocation");
return dSet;
}
catch (Exception ex)
{
throw (ex);
}
finally
{
con.Close();
}
}
I called the method with "Test" as parameter(which is some location value of some Items in Items table) and I get an Soap exception which tells me that there is no column of the name "Test".
I don't understand why i get this exception.
Thanks In Advance
August 29, 2006 at 11:26 am
Your parameter needs to be enclosed in quotes, or TSQL will interpret it as a column name, not a parameter value.
August 29, 2006 at 11:28 am
Clarification:
SqlDataAdapter cmdItemTypes = new SqlDataAdapter("Select ItemName,ItemModel,PurchaseDate,Location,DepartureDate,ItemType,AdditionalInfo From Items Where Location = " + location + "", con);
should be written as...
SqlDataAdapter cmdItemTypes = new SqlDataAdapter("Select ItemName,ItemModel,PurchaseDate,Location,DepartureDate,ItemType,AdditionalInfo From Items Where Location = '" + location + "'", con);
It's hard to see, but location is now 'location'.
Hope that makes sense.
August 29, 2006 at 4:37 pm
You were right.
Thanks.
Viewing 4 posts - 1 through 4 (of 4 total)
You must be logged in to reply to this topic. Login to reply