Hi, im looking for a simple code where i can for example have 1 record from my access database as a label.
I am creating a shopping website so my database consists of product names. i want one of these products names to come up as a label in my asp.net page.
You can use Database.QuerySingle to read one record, or Database.QueryValue to read one value such as a product name:
@{
var db= Database.Open("MyConnectionStringName")
var product = db.QueryValue("Select ProductName From Products WHERE ProductId = @0, Request["productId"]);
}
<span>@product</span>
Hi, im using asp.net webmatrix and still new to this, i didnt manage to get any information (that i really understood) from that link haha. Will i stil be able to use that code you gave me in webmatrix? thanks anyway for your help
That code is for WebMatrix (ASP.NET Web Pages). I think you had better start at the first tutorial and work your way through them otherwise nothing else is likely to make sense to you.
razzied104
Member
9 Points
7 Posts
displaying access database record as a label on asp.net webmatrix page
Mar 24, 2012 10:48 PM|LINK
Hi, im looking for a simple code where i can for example have 1 record from my access database as a label.
I am creating a shopping website so my database consists of product names. i want one of these products names to come up as a label in my asp.net page.
Can anyone help?
Thanks so much
Mikesdotnett...
All-Star
154955 Points
19872 Posts
Moderator
MVP
Re: displaying access database record as a label on asp.net webmatrix page
Mar 25, 2012 06:44 AM|LINK
You can use Database.QuerySingle to read one record, or Database.QueryValue to read one value such as a product name:
@{ var db= Database.Open("MyConnectionStringName") var product = db.QueryValue("Select ProductName From Products WHERE ProductId = @0, Request["productId"]); } <span>@product</span>Read this tutorial for more information on working with data in Web Pages: http://www.asp.net/web-pages/tutorials/data/5-working-with-data
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
razzied104
Member
9 Points
7 Posts
Re: displaying access database record as a label on asp.net webmatrix page
Mar 25, 2012 09:42 PM|LINK
Hi, im using asp.net webmatrix and still new to this, i didnt manage to get any information (that i really understood) from that link haha. Will i stil be able to use that code you gave me in webmatrix? thanks anyway for your help
Dino He - MS...
Star
8068 Points
1023 Posts
Microsoft
Re: displaying access database record as a label on asp.net webmatrix page
Mar 26, 2012 03:16 AM|LINK
Hi
You can create a cshtml file then use the code the Mike provide to you.
I think it should work.
change the SQL querystring to your own.
Regards
If you have any feedback about my replies, please contact msdnmg@microsoft.com
Microsoft One Code Framework
Mikesdotnett...
All-Star
154955 Points
19872 Posts
Moderator
MVP
Re: displaying access database record as a label on asp.net webmatrix page
Mar 26, 2012 04:56 AM|LINK
That code is for WebMatrix (ASP.NET Web Pages). I think you had better start at the first tutorial and work your way through them otherwise nothing else is likely to make sense to you.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter