SQL Clone
SQLServerCentral is supported by Redgate
Log in  ::  Register  ::  Not logged in

looping through date range variable in c#

looping through date range variable in c#

Ten Centuries
Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)Ten Centuries (1.2K reputation)

Group: General Forum Members
Points: 1236 Visits: 682
C# code to update a webservice link that loops through multiple dates (datefrom to dateto )using variable in for script task example if the date range was between 2013-01-01 -2013-01-04 it loop through the dates and supply the xml source the updated values -

The original VB code is below –
Dts.Variables("User::XMLPathDaily").Value = "http://XXXX&dateFrom="
Dts.Variables("User::XMLPathDaily").Value = Dts.Variables("User::XMLPathDaily").Value + Dts.Variables("User::XMLRunDay").Value
Dts.Variables("User::XMLPathDaily").Value = Dts.Variables("User::XMLPathDaily").Value + "&dateTo=" + Dts.Variables("User::XMLRunDay").Value + "&customField=1 "
'Sleep for 5 Seconds else cannot re-try connection
Dim sec As Double = 5 'Convert.ToDouble(Dts.Variables("intDelaySecs").Value)
Dim ms As Int32 = Convert.ToInt32(sec * 1000)

This is the c# code I want to update –
C# code in script task
#region Namespaces
using System;
using System.Net; //Added
using Microsoft.SqlServer.Dts.Runtime; //Added
using System.Windows.Forms;

namespace ST_5fd2f54a0c7f4813995b1208caacd6f4

public partial class ScriptMain : Microsoft.SqlServer.Dts.Tasks.ScriptTask.VSTARTScriptObjectModelBase
public void Main()
// Declare variable that will hold the xml document received by the API
string xmlDoc2 = String.Empty;

// Get the URI from the variable
string url = Dts.Variables["User::URI2"].Value.ToString();


//Create a Web Client
using (WebClient client = new WebClient())
//Download the xml document as a string
xmlDoc2 = client.DownloadString(url);
client.DownloadFile(url, "c:\\xmlfromurl.xml");

// Set the value of the xmlDocument to the string that was just downloaded
Dts.Variables["User::xmlDoc2"].Value = xmlDoc2;
Dts.TaskResult = (int)ScriptResults.Success;
Dts.TaskResult = (int)ScriptResults.Failure;

#region ScriptResults declaration

/// This enum provides a convenient shorthand within the scope of this class for setting the
/// result of the script.
/// This code was generated automatically.
enum ScriptResults
Success = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Success,
Failure = Microsoft.SqlServer.Dts.Runtime.DTSExecResult.Failure


Any advice would be greatly appreciated.


You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum