Joseph Michael Pesch
VP Programming

C# Character Code Example

by 24. October 2010 13:27

for (int i = 48; i <= 57; i++) // 0 through 9

  System.Diagnostics.Debug.WriteLine((char)i);

for (int i = 65; i <= 90; i++) // A through Z

  System.Diagnostics.Debug.WriteLine((char)i);

for (int i = 97; i <= 122; i++) // a through z

  System.Diagnostics.Debug.WriteLine((char)i);

 

Tags:

C#

MS CRM Set Lookup Value

by 15. October 2010 17:26

new_contactresearchphone entity = new new_contactresearchphone();

// Set new_clientid (contact reference) lookup to value of empty guid

entity.new_clientid = new Lookup { Value = Guid.Empty

, type = EntityName.contact.ToString() };

Tags:

[None]

MS CRM Set Picklist Value

by 15. October 2010 17:23

// Set new_clienttype picklist value to 2

entity.new_clienttype = new Picklist() { name = "new_clienttype", Value = Convert.ToInt16(2) };

Tags:

MS CRM

Open Excel as .Net DataSet in C#

by 12. October 2010 17:26

This entry shows how to open an Excel file as a standard .Net dataset.  This method uses an OleDb driver provided by Microsoft, it does not require that Excel is loaded on the machine, only the OleDb driver is needed.

 

OleDbConnection con = new OleDbConnection(

  "Provider=Microsoft.ACE.OLEDB.12.0; Extended Properties=Excel 12.0;"

  + "Data Source=" + FilePath);

 

 

Driver Download:

http://www.microsoft.com/downloads/en/details.aspx?FamilyID=7554F536-8C28-4598-9B72-EF94E038C891&displaylang=en

 

 

static public class ExcelDataSetUtil

  {

 

    static public DataSet GetDataSet(string FilePath, string SheetName, bool HasHeader)

    {

      //OleDbConnection con = new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source="

      //                    + FilePath + ";Extended Properties=\"Excel 8.0;"

      //                    + "HDR=" + (HasHeader ? "Yes" : "No") + ";IMEX=1\"");

 

      OleDbConnection con = new OleDbConnection(

        "Provider=Microsoft.ACE.OLEDB.12.0; Extended Properties=Excel 12.0;"

        + "Data Source=" + FilePath);

      con.Open();

      DataSet ExcelDS = new DataSet();

      try

      {

        //Create Dataset and fill with imformation from the Excel Spreadsheet for easier reference

        OleDbDataAdapter cmd = new OleDbDataAdapter(" SELECT * FROM [" + SheetName + "$]", con);

        cmd.Fill(ExcelDS);

        con.Close();

      }

      catch (Exception ex)

      {

        System.Diagnostics.Debug.WriteLine(ex.ToString());

        throw;

      }

      finally

      {

        con.Close();

      }

      return ExcelDS;

    }

 

    static public void GetDataSet_SampleProcessing(string FilePath, string SheetName, bool HasHeader)

    {

      DataSet ExcelDS = GetDataSet(FilePath, SheetName, HasHeader);

 

      try

      {

        //Travers through each row in the dataset

        foreach (DataRow row in ExcelDS.Tables[0].Rows)

        {

          //Stores info in Datarow into an array

          Object[] cells = row.ItemArray;

          //Traverse through each array and put into object cellContent as type Object

          //Using Object as for some reason the Dataset reads some blank value which

          //causes a hissy fit when trying to read. By using object I can convert to

          //String at a later point.

          foreach (object cellContent in cells)

          {

            //Convert object cellContect into String to read whilst replacing Line Breaks with a defined character

            string cellText = cellContent.ToString();

            cellText = cellText.Replace("\n", "|");

            //Read the string and put into Array of characters chars

            System.Diagnostics.Debug.WriteLine(cellText);

          }

        }

      }

      catch (Exception ex)

      {

        System.Diagnostics.Debug.WriteLine(ex.ToString());

        throw;

      }

    }

  }

 

 

Tags:

[None]

Slow SSIS Package

by 11. October 2010 21:22

http://www.sqlmonster.com/Uwe/Forum.aspx/sql-server-dts/8025/SSIS-OleDB-source-as-table-view-Hideously-Slow

The difference between my SSIS package and the Export Wizard's package was
that the wizard chose an "Sql command" Data Access Method (and simply said
SELECT * FROM view)  where I chose the "Table / View" Data Access Method.

The type of Data Access Method selected apparently makes a HUGE difference
in response time.

Tags:

[None]