?
Solved

ArrayList

Posted on 2007-04-03
6
Medium Priority
?
736 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 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
Get your Conversational Ransomware Defense e‑book

This e-book gives you an insight into the ransomware threat and reviews the fundamentals of top-notch ransomware preparedness and recovery. To help you protect yourself and your organization. The initial infection may be inevitable, so the best protection is to be fully prepared.

 

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

Technology Partners: 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

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…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Suggested Courses

840 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