Wednesday, March 7, 2012

Programmatically add ArrayList into to Sqldatasource.

I am trying to add a number of dates into a Sql database. Basically I want the user to add the start and end date and then all the dates in between are are added to a database in unique records. I can create an ArrayList but I don't know how to bind it to an SqlDataSource


Dim startdateAs DateTime = tbstartdate.Text
Dim enddateAs DateTime = tbenddate.Text
Dim datediffAs TimeSpan = enddate.Subtract(startdate)
Dim noofdaysAs Integer = datediff.Days

Dim arAs New ArrayList
Dim i
For i = 0To noofdays
ar.Add(startdate.AddDays(i))
Next

Sorry if this is a total noob question...

You can not pass arraylist to sql data source. The simplest option would be to pass the start date and the end date to the sql stored procedure and in the stored procedure loop though the dates(between startdate and enddate) to add unique records.

No comments:

Post a Comment