April 2007 - Posts

How to execute a DTS Package

Executing a DTS package from .Net has never been simpler. Here's how:

 '----------------------------------------------------------------------------------------------------------------------
' NOTE: Requires reference to Microsoft DTS Package Object Library
'----------------------------------------------------------------------------------------------------------------------

Dim oPackage As New DTS.Package

oPackage.LoadFromSQLServer sServerName, sUID, sPWD, DTSSQLStgFlag_Default, "", "", "", "MyPackageName", 0

oPackage.Execute

Set oPackage = Nothing

Cheers,

Obi

How to Format Dates in .Net

 '-------------------------------------------------------------------------------------
' Determines the date of the Sunday of the week for the incoming date
'-------------------------------------------------------------------------------------
Function GetSundayDate(strDateIn)

   dim intDayOfWeek

   intDayOfWeek = weekday(strDateIn, 1)
   intDayOfWeek = (intDayOfWeek * (-1)) + 1

   GetSundayDate = formatdate(dateadd("d",strDateIn ,intDayOfWeek))
  
End Function


'-------------------------------------------------------------------------------------
' Formats a date in mm/dd/yyyy format
'-------------------------------------------------------------------------------------
Function FormatDate(strDateIn)

   FormatDate = datepart("m", strDateIn) & "/" & datepart("d", strDateIn) & "/" & datepart("yyyy", strDateIn)
  
End Function


'-------------------------------------------------------------------------------------
' Returns a formatted "hh:mm AM/PM" string for the incoming 24-hour formatted time
'-------------------------------------------------------------------------------------
Function FormatTime(intTime)

   dim strTime

   if intTime < 1000 then
      strTime = cstr(intTime)
      FormatTime = left(strTime,1) & ":" & right(strTime,2) & " AM"
   elseif intTime < 1200 then
      strTime = cstr(intTime)
      FormatTime = left(strTime,2) & ":" & right(strTime,2) & " AM"
   elseif intTime < 1300 then
      strTime = cstr(intTime)
      FormatTime = left(strTime,2) & ":" & right(strTime,2) & " PM"
   else
      strTime = cstr(intTime - 1200)
      FormatTime = left(strTime,1) & ":" & right(strTime,2) & " PM"
   end if

End Function


'-------------------------------------------------------------------------------------
' Returns a mm/dd/yy formatted date for the incoming Sunday date and the requested day of the week
'-------------------------------------------------------------------------------------
Function GetDate(strDateIn, intDayOfWeek)

   GetDate = formatdate(dateadd("d", intDayOfWeek, strDateIn))

End Function

Happy Coding,

Obi

 

How to Deserialize an XML Document into an Object

A simple yet useful way to demonstrate how to take an XML document, and deserialize it to rehydrate an object:

string xmlStuff = TaxReturnXMLDoc.OuterXml;
TextReader reader = new StreamReader(@"C:\temp\Efile-SerializedTaxReturnObject-Clean.xml");
XmlSerializer serializer = new XmlSerializer(typeof(TaxReturnEntity));
TaxReturnEntity tre = (TaxReturnEntity)serializer.Deserialize(reader);
reader.Close();

Obi

How to Pass Values Between Two Web forms

Expose the values you want to access in other pages as proprties of the current page class. This method requires you to code extra properties that you can access in another web form.

The entire process works as follows:

1. Create the web form with controls

2. Create property Get procedures that will return control values

3. Provide some button or link button that posts the form back

4. In the button click event handler call Server.Transfer method that will transfer execution to the specified form

5. In the second form you can get a reference to the first form instance by using Context.Handler property. Then you will use the get properties we created to access the control values.

--------------Source Web Form----------------

Add following properties to the web form:

public string Name

{

   get

   {

      return TextBox1.Text;

   }

}

 

public string EMail

{

   get

   {

      return TextBox2.Text;

   }

}

 

Now, call Server.Transfer.

private void Button1_Click (object sender, System.EventArgs e)

{

   Server.Transfer("anotherwebform.aspx");

}

 

----------------------------------------

Destination Web Form

----------------------------------------

private void Page_Load (object sender, System.EventArgs e)

{

   //create instance of source web form

   WebForm1 wf1;

 

   //get reference to current handler instance

   wf1=(WebForm1)Context.Handler;

   Label1.Text=wf1.Name;

   Label2.Text=wf1.EMail;

}

Cheers,

Obi

 

Orcas is here baby!

Folks,

I haven't been very active in my blog posts lately. This is largely due to the fact that my life has been flat out like a lizard drinking (aussie expression for being busy)!

There is never a dull moment in my household, so lately I have been tinkering with some cool Microsoft products such as the Microsoft Office Professional 2007 and the like.

The Redmond guys keep rolling out the good stuff.  Before, I even realize a sense of pleasure or satisfaction (if you will), a newer version of Visual Studio or Sql Server is rolled out.

Talking about Visual Studio, the next version code name "Orcas" is ready for download. Orcas mainly targets Windows Vista and the .NET Framework 3.0 Development.  It consists of the following new features:

·         Create Microsoft Office Applications with full integration of VSTO into VS

·         Handle Data More Smoothly with LINQ

·         Enable New Web Experience with client-side execution using ASP.NET AJAX and other enhancements.

·         Improve Application Life-Cycle Management (ALM)

I can go on and on to extol its goodness, but suffice to say, this is a cool stuff and I suggest that you check out the Orcas_March07CTP

Cheers,

Obi