Reputation: 1129
hello i build a webservice to communicate with the iPhone.
i want to display the rooms from the selected street in a table, to do that i must to pass some id's from my iPhone with JSON to the sql database over a asp.net webservice.
my webmethod look like this:
[ScriptMethod(ResponseFormat = ResponseFormat.Json)]
[WebMethod]
public string Room(string street_id, string country_id, string city_id)
{
return RoomHelper.Room(street_id, country_id, city_id);
}
My sql statement should look like this:
SELECT Roomname FROM Room WHERE street_id = (passed street_id) AND country_id = (passed country_id) AND city_id = (passed city_id)
how can i use the passed parameters in my sql statement to filter the rooms ?
Upvotes: 1
Views: 799
Reputation: 4754
using (SqlConnection conn = new SqlConnection("<my connection string>"))
{
conn.Open();
using (SqlCommand cmd = new SqlCommand("SELECT Roomname FROM Room WHERE street_id = @streetId AND country_id = @countryId AND city_id = @cityId", conn))
{
cmd.Parameters.AddWithValue("@streetId", street_id);
cmd.Parameters.AddWithValue("@countryId", country_id);
cmd.Parameters.AddWithValue("@cityId", city_id);
using (var reader = cmd.ExecuteReader())
{
// retrieve your data per row or as you wish
while (reader.Read())
{
}
}
}
}
Upvotes: 1