Hi, I run into an interesting thing. I'm looking into SQL a bit, and was reading some tutorial on W3C, so I built a small application to play with SQL queries: inserting info in a table and then retrieve it as it is, filter it etc.
The table contains 5 columns: Id(int and primary key), Name (nvarchar), Surname (nvarchar), Town (nvarchar), Price (decimal) and the data is inserted upon submission of a form. Now, I was trying to retrieve all the surnames and prices of all people living in London. The query in itself is pretty simple: SELECT Surname,Price FROM transactions WHERE Town='London'
but there is a problem: I want to display the results in a label as its value and therefore I need another table where copying these results. Here is the full code but unfortunately I get an error, the compiler complains about the "AS":
protected void displayLondonPrices(object sender, EventArgs e) {
string londonPrice;
hookup = new SqlConnection("Server=localhost\\SqlExpress;Database=tests;" + "Integrated Security=True");
strInsert = "SELECT Surname,Price FROM transactions AS Londoners WHERE Town='London'";
sqlCmd = new SqlCommand(strInsert, hookup);
hookup.Open();
reader = sqlCmd.ExecuteReader();
while (reader.Read()) {
londonPrice = Convert.ToString(reader["Londoners"]);
queryResults.Text = "Total in London is " + londonPrice;
}
reader.Close();
hookup.Close();
}
Essentially, I need something that the reader can read, which is why I used AS Londoners
in the query. Is there another way?