?
Solved

ArrayList

Posted on 2007-04-03
6
Medium Priority
?
733 Views
Last Modified: 2013-11-26
Hi,

I'm using ASP.NET 2005 with SQL Server.  I need to create an array to store 2 values which are StartDate and EndDate.  The dates will be used as stored procedure parameters to pass to SQL Server. I need to store the StartDate and EndDate into the array.  I created an ArrayList, but was not sure how to go about getting the EndDate value. Do I concatenate the StartDate and EndDate and then retrieve the values?  Could someone show me an example of creating the ArrayList and then retrieving both values using an iteration because I could have more than one StartDate and EndDate values? My code so far is as follows:

‘Assumption:  The ArrayList gets its data by an ADO.NET DataTable.

Dim DateRange As String
DateRange = rdrStartDate + " " + rdrEndDate
                        arrList.Add(DateRange)

Thanks,
Denise
0
Comment
Question by:DeniseGoodheart
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
6 Comments
 
LVL 18

Accepted Solution

by:
Elvio Lujan earned 1840 total points
ID: 18846556
you can create a structure that way:

        Private Structure dates
            Dim StartDate As DateTime
            Dim EndDate As DateTime
        End Structure

Dim DateRange As dates
DateRange.StartDate = rdrStartDate
DateRange.EndDate = rdrEndDate
arrList.Add(DateRange)
0
 
LVL 22

Assisted Solution

by:_TAD_
_TAD_ earned 160 total points
ID: 18846628

An arraylist stores an object. That Object could be anything - including another array or paired object.


                  ArrayList lst = new ArrayList();

                  lst.Add(new string[]{"Start1","End1"});
                  lst.Add(new string[]{"Start2","End2"});
                  lst.Add(new string[]{"Start3","End3"});

                  string[] str;
                  for (int i=0;i<lst.Count;i++)
                  {
                        str = (string[])lst[i];
                        Console.WriteLine("Start Date is: {0}", str[0]);
                        Console.WriteLine("End Date is: {0}", str[1]);
                  }
0
 

Author Comment

by:DeniseGoodheart
ID: 18846791
Hi lem2802:

Thanks for your code.  How do I create the iteration loop to retrieve the values?  I tried the following with no success.

Private Sub TestArrayList()
        Dim pStartDate As dates
        Dim pEndDate As dates
        Dim i As Integer
        For i = 0 To arrList.Count - 1
            pStartDate = arrList.Item(0)
            pEndDate = arrList.Item(1)
        Next
    End Sub

Thanks,
Denise
0
Windows Server 2016: All you need to know

Learn about Hyper-V features that increase functionality and usability of Microsoft Windows Server 2016. Also, throughout this eBook, you’ll find some basic PowerShell examples that will help you leverage the scripts in your environments!

 

Author Comment

by:DeniseGoodheart
ID: 18846811
Hi TAD:

Thanks for your code.  How to I get the values?  I tried the following with no success:

Private Sub TestArrayList2()

        Dim paramStartDate As String
        Dim paramEndDate As String

        Dim i As Integer = 0
        Do While (i < lst.Count)
            paramStartDate = lst(0)
            paramEndDate = lst(1)
            i = (i + 1)
        Loop
Thanks,
Denise
0
 
LVL 18

Assisted Solution

by:Elvio Lujan
Elvio Lujan earned 1840 total points
ID: 18846904
Private Sub TestArrayList()
        Dim p As dates
        Dim i As Integer
        For i = 0 To arrList.Count - 1
            p.StartDate = ctype(arrList.Item(i), dates).StartDate
            p.EndDate = ctype(arrList.Item(i), dates).EndDate
         Next
    End Sub
0
 

Author Comment

by:DeniseGoodheart
ID: 18847005
Many thanks,
Denise
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This document covers how to connect to SQL Server and browse its contents.  It is meant for those new to Visual Studio and/or working with Microsoft SQL Server.  It is not a guide to building SQL Server database connections in your code.  This is mo…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question