Solved

ArrayList

Posted on 2007-04-03
6
725 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
  • 3
  • 2
6 Comments
 
LVL 17

Accepted Solution

by:
lem2802 earned 460 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 40 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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

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 17

Assisted Solution

by:lem2802
lem2802 earned 460 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

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
Get a first impression of how PRTG looks and learn how it works.   This video is a short introduction to PRTG, as an initial overview or as a quick start for new PRTG users.

705 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now