Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
|
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old August 27th, 2003, 09:04 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default ADO.NET with ASP.NET

I'm new to both and I'm trying to pull records out of a database and assign them to a variable. Here is my code thus far:

<%#monthname(datepart("m", Container.DataItem("event_date")))%>

I can't figure out how to assign that to a variable. Any suggestions?
 
Old August 27th, 2003, 10:29 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

I think you're mixing up two concepts: In-line script and Data Binding.

The code below using the # character is used to "bind" data from the DataItem to a textbox, a label, or whatever object you're trying to bind it to.

To assign values to a variable, you'll need to create a script block that defines the variable, and then retrieves its value from some sort of data source (in this case).

So, if Container.DataItem references to a DataReader you declared somewhere in your code, you'll need to retrieve the value for a variable from that DataReader. How you do that, depends on the other code for your page. So, to be able to give some advice, it's necessary that you post the rest of your code.

Cheers,


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old August 27th, 2003, 12:13 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Thanks for the advice. I'm going to read the chapter on ado.net. I skipped it because I didn't think it was important :). Now I realize ado.net is the way to go when you're working with data.
 
Old August 27th, 2003, 12:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

ADO.NET is pretty important if you want to work with data from some Data Source. ADO.NET allows you to connect to databases like Access, SQL Server, Oracle, etc. and stuff like XML and text files.

Even the databinding expression you used (Container.DataItem) is most likely based on some ADO.NET object......


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
 
Old September 2nd, 2003, 09:28 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
Default

Quote:
quote:Originally posted by Imar
 Hi there,

To assign values to a variable, you'll need to create a script block that defines the variable, and then retrieves its value from some sort of data source (in this case).

Cheers,


Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.
All the books I have use binding examples with ado.net. Can you provide the proper syntax to assign values to a variable? Thanks.
 
Old September 2nd, 2003, 11:47 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It all depends on the datasource you have. For example, if you have a DataSet called ds, the following code would assign the first column of the first row to a variable called Name:

Code:
Name = ds.Tables[0].Rows[0][0].ToString();
You could do this in a loop (replace Rows[0] with Rows[LoopCounter]) to retrieve multiple rows from the dataset.

If you need more columns, change the last [0] to [1], or use the name of the colum, for example:

Code:
Name = ds.Tables[0].Rows[0]["CustomerName"].ToString();
I suggest you check out the DataSet class in the SDK or at http://msdn.microsoft.com (http://msdn.microsoft.com/library/de...asp?frame=true).

Cheers,

Imar


---------------------------------------
Imar Spaanjaars
Everyone is unique, except for me.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Can you use Asp 3.0 with ADO.NET? handles Classic ASP Basics 0 September 30th, 2005 07:37 PM
'like' problem with asp.net/ ado badgolfer Access ASP 2 September 16th, 2004 01:50 PM
ado.net with asp.net stu9820 ASP.NET 1.0 and 1.1 Basics 2 August 27th, 2003 08:59 AM
Beginning ASP.NET E-Commerce (ADO error) dianastudy3 All Other Wrox Books 3 July 30th, 2003 11:51 PM
MSDE and SQL CE (using VB.NET and ADO.NET) LEGS ADO.NET 0 July 12th, 2003 11:27 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.