Reputation: 159
Really new to SQL and I have spent days trying to do queries in my windows store app but can not get the where clause to work
I use the following code to query my database
string query = string.Empty;
public async Task<List<CityClass>> GetListCities(int fred)
{
List<CityClass> objLstCoty = new List<CityClass>();
try
{
query = "Select " + DBColumns.Id + "," + DBColumns.WORKNUM + "," + DBColumns.FAULTREF + " from " + DataBaseWrapper.Cities;
objLstCoty = await con.QueryAsync<CityClass>(query);
tb1.Text = "ID: " + objLstCoty[fred].Id;
tb2.Text = "Fault Ref: " + objLstCoty[fred].FAULTREF;
tb3.Text = "Work Number: " + objLstCoty[fred].WORKNUM;
}
catch (Exception ex)
{
//return null;
throw ex;
}
return objLstCoty;
}
This query 3 columns in my database and puts the data into 3 textboxs
How do I add a where statement so that it only returns the data where the WORKNUM
equals a certain number eg WORKNUM = "112000"
I Thought adding + " where " + DBColumns.WORKNUM = "112000";
would work but it does not
Any Help is appreciated
Mark
Upvotes: 0
Views: 120
Reputation: 159
Thanks for all your help guiding me in the right direction I managed to get it to work using
var ITEM = db.Query("Select * From Cities where WORKNUM='" + srcnum + "' ").FirstOrDefault();
where srcnum is the number i wanted to search for in the WORKNUM column
i can then just fill the textblocks using item.[columnname]
Mark
Upvotes: 1
Reputation: 5910
Looking at how you would add that WHERE
clause to the end of your query, it wouldn't even compile as the =
sign is outside of the string you're building up.
Try doing the following:
query = "Select " + DBColumns.Id + "," + DBColumns.WORKNUM + "," + DBColumns.FAULTREF + " from " + DataBaseWrapper.Cities + " where " + DBColumns.WORKNUM + " = 112000";
Upvotes: 0