I have been looking around the internet for a way to display specific content from a sql data table. I was hoping that I could display the Content column according to the Id column value.
alt text http://photos-h.ak.fbcdn.net/hphotos-ak-snc3/hs031.snc3/11852_1241994617732_1465331687_655971_2468696_n.jpg
I have been looking around the internet for a way to display specific content
Share
If you want to have exactly one value from one single record, you can use the
ExecuteScalarmethod of theSqlCommandclass:If you want to be able to do this for various ids, do not just concatenate a new sql string. I will repeat that: do not just concatenate a new sql string. Use parameters instead:
Update
Sample aspx page. First some markup (let’s say the file is called example.aspx):
…and in the code-behind (that would be called example.aspx.cs; I have included only the Page_Load event for simplicity):
Disclaimer: the code is written directly into the answer window and not tested (I don’t have access to a development environment right now) so there may be errors