Solved

ArrayList

Posted on 2007-04-03
6
730 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 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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 

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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In my previous two articles we discussed Binary Serialization (http://www.experts-exchange.com/A_4362.html) and XML Serialization (http://www.experts-exchange.com/A_4425.html). In this article we will try to know more about SOAP (Simple Object Acces…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
Come and listen to Percona CEO Peter Zaitsev discuss what’s new in Percona open source software, including Percona Server for MySQL (https://www.percona.com/software/mysql-database/percona-server) and MongoDB (https://www.percona.com/software/mongo-…
Monitoring a network: how to monitor network services and why? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the philosophy behind service monitoring and why a handshake validation is critical in network monitoring. Software utilized …

717 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