Wrox Programmer Forums
Go Back   Wrox Programmer Forums > SQL Server > SQL Server ASP
|
SQL Server ASP Discussions about ASP programming with Microsoft's SQL Server. For more ASP forums, see the ASP forum category.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Server ASP 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 June 1st, 2004, 05:24 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default How Can I Use Arrays with SQL Server Data?

Please could someone help me with the following problem:

I have an 'update your details page' where customers can amend their details. This is an ASP page with various form boxes with data populating these fields from a SQL Server database.

One column in the database contains a customers childrens names which has been populated in the following way: david, julie, sarah, diane

On my update page there needs to be 4 text boxes for childrens names. I have used the split array function to split these names into separate boxes.

Dim ChildrenArray
ChildrenArray = split(rs_Users.Fields.Item("childrensNames").Value , ",")

So the value of text box 'childname1' is 'ChildrenArray(0)' and so on.

This is fine IF there are 4 names in the database. However, a customer could have no children, 1 child, 3 children etc.

How can I amend the code to take this into account?

At the moment, if there are 3 childrens names, I get an error message on my ASP update page for the value 'ChildrenArray(3)' in text box 'childname4' because there isn't one!!

I don't really know much about arrays so all help greatly appreciated.

Thanks in advance

Lucy

 
Old June 1st, 2004, 06:49 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Lucy,

When the customer has no children, the column in your database should contain nothing there. So based on that you can always not show textboxes for children there.

May be if you check for the data in column corrsponding to Children in the database and dynamically generate the textboxes, you can get the needed number of text boxes alone populated there on your page.

Imagine a situation when the customer who had no children till yesterday has a child today. If you want to update his details, you need to add one text box there on his update page, in that case are you dynamically letting the user to add a nex textbox? Also when you have that feature of adding new textboxes in addition to what you show that, you got to check for number of text boxes that are shown there and based on that you got to compose them all into a string to write it back to the database.

I would suggest you to go for a LIST box, which would be easy to manage.

Let me explain about the LIST box here.
If no Child - The list box contains nothing.
If 2 or 3 children - The list bos can show whatever is there in your table.
If in case you need to add another child there, You can always do that, by having a single textbox and ask the user to enter the new child's name and that can be added to the LIST box. Even delete is possible, when made some mistake/really wanted to delete the data from there.

Finally, while updating the customers data, you can loop through all the values in the LIST box and compose them in to a string at one shot and write it into the DB with no pain.

So you can give a thought for it.
Post here for any clarifications.
Hope that helps.
Cheers!

_________________________
-Vijay G
Strive for Perfection
 
Old June 14th, 2004, 05:15 AM
Authorized User
 
Join Date: Jul 2003
Posts: 56
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Hiya

Thanks for replying - somehow I knew it wasn't going to be easy! Wicked suggestion about putting everything in a list box. Will get on the case now :D

Cheers for your help

Lucy xx

 
Old June 14th, 2004, 05:33 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 184
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Jonax
Default

On a side note:
I would store the children in a separate (database)table, one row each...

 
Old June 14th, 2004, 01:20 PM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 2,480
Thanks: 0
Thanked 1 Time in 1 Post
Default

Hi Lucy,
If that's going to be wicked suggestion, then let me know whichever way you finally choose to implement this. All the best.

Yea Jonax,
That too was in my mind putting them in different table, but got to use another set of hops from ASP to put them all in to the db, whenever the customer data is updated, so thought of putting them in once table with comma separated. Thought one would not have too many children, to cause too many a headache that way;)

Cheers!

_________________________
-Vijay G
Strive for Perfection





Similar Threads
Thread Thread Starter Forum Replies Last Post
Import data from sql server using biztalk server kaushalparik Biztalk 0 July 22nd, 2008 06:16 AM
SQL Server vs Arrays Bryan_Homey ASP.NET 2.0 Basics 2 August 18th, 2006 01:21 AM
Multilanguage Data in Sql Server tiyyob SQL Server 2000 3 June 14th, 2006 01:51 PM
SQL Server data types spinout SQL Server 2000 5 September 23rd, 2004 02:27 AM
Using Access with SQL Server Data npepin Access 4 July 21st, 2004 03:36 PM





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