 |
| 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
|
|
|
|

August 27th, 2003, 09:04 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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?
|
|

August 27th, 2003, 10:29 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

August 27th, 2003, 12:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

August 27th, 2003, 12:27 PM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|

September 2nd, 2003, 09:28 AM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 1,110
Thanks: 0
Thanked 3 Times in 3 Posts
|
|
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.
|
|

September 2nd, 2003, 11:47 AM
|
 |
Wrox Author
|
|
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
|
|
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.
|
|
 |