NET : Create Dynamic SqlCommand Parameters

string IDs = “2055,1644,5889”;
List<string>
IDNumbers = IDs.Split(‘,’).ToList<string>();
StringBuilder sb = new
StringBuilder();
cmd = conn.CreateCommand();
cmd.CommandType = CommandType.Text;
sb.Append(“SELECT
* FROM TABLE WHERE (“
);
//build parameters
foreach (string idNumber in IDNumbers)
{
sb.Append(“TABLE.ID
= “
+ “:parm” +
idNumber.ToString());
sb.Append(” OR
);
}
sb.Remove(sb.Length – 3, 3);
sb.Append(“)
);
foreach (string idNumber in IDNumbers)
{
cmd.Parameters.Add(new
OracleParameter(“parm” +
idNumber.ToString(), idNumber));
}
cmd.ExecuteNonQuery();

NET : Easily Get DLL Assembly Info Via Visual Studio

Unfortunately, I had to try and remember how to easily get DLL information without going into the GAC. However, fortunately, there is easy way to get DLL assembly information ( including token, culture, & version ) directly from Visual Studio :

  1. Open your Visual Studio Solution
  2. Set a breakpoint and run in debug mode
  3. Open the Immediate Window
  4. Enter the path to your DLL using System.Reflection:

    ?System.Reflection.Assembly.LoadFile (@”C:VSSWebSoluablebinAjaxControlToolkit.dll”).FullName

    And you should receive something similar to the following:

      “AjaxControlToolkit, Version=3.5.11119.20050, Culture=neutral, PublicKeyToken=28f01b0e84b6d53e”

      St. Louis Day Of .NET

      This is late coming, but I wanted to make sure I comment on this year’s St. Louis Day of Dot Net . It was awesome! Microsoft “Lightswitch” was introduced. I caught up to HTML5 technology, as well as many others, and it was great.

      The yearly event was started in 2008 by the St Louis .NET user group. Many props to this group and the generous sponsors. This year, 800 people attended the conference — ranging from developers, architects, quality assurance, managers, designers, DBAs and other technology positions.

      It seems that most went away happy, satisfied, with a better understanding and encouragement to learn more about new technologies in .NET, databases, website development, architecture principles and software development in general.

      Also, thanks to my company for letting me attend these types of events. They are short enough to attend but provide enough information that I get my motivation re-charged.

      Visual Basic Operators: ‘AndAlso’ & ‘OrElse’

      Since I’ve mostly been using C# for the past few years, I sometimes get confused when I come across a Visual Basic application and have to distinguish between the newer operators (OrElse, AndALso vs Or, And)

      Operator: OrElse

      This example uses the OrElse operator to perform logical disjunction on two expressions. The result is a Boolean value that represents whether either of the two expressions is true. If the first expression is True, the second is not evaluated. If the first expression is false then the second expression is evaluated.

      Dim A As Integer = 10
      Dim B As Integer = 8
      Dim C As Integer = 6
      Dim myCheck As Boolean
      myCheck = A > B OrElse B > C ‘ True. Second expression is not evaluated.
      myCheck = B > A OrElse B > C ‘ True. Second expression is evaluated.
      myCheck = B > A OrElse C > B ‘ False.

      Operator: Or (if either expression evaluates to true then true will be returned)

      Dim A As Integer = 10
      Dim B As Integer = 8
      Dim C As Integer = 6
      Dim myCheck As Boolean
      myCheck = A > B Or B > C ‘ Returns True.
      myCheck = B > A Or B > C ‘ Returns True.
      myCheck = B > A Or C > B ‘ Returns False.

      Operator: AndAlso (if first expression evaluates to false then second expression is not evaluated)

      Dim a As Integer = 10
      Dim b As Integer = 8
      Dim c As Integer = 6
      Dim firstCheck, secondCheck, thirdCheck As Boolean
      firstCheck = a > b AndAlso b > c ‘ Returns True.
      secondCheck = b > a AndAlso b > c ‘ Returns False
      thirdCheck = a > b AndAlso c > b ‘ Returns False

      Operator: And (both expressions are evaluated)

      Dim a As Integer = 10
      Dim b As Integer = 8
      Dim c As Integer = 6
      Dim firstCheck, secondCheck As Boolean
      firstCheck = a > b And b > c ‘ Returns True.
      secondCheck = b > a And b > c ‘ Returns False

      Ideally, the short circuit operations, you’re saving on the extra condition check when the first one is satisfied (OrElse) or not satisfied (AndAlso). So these should give you better performance in general.

      OrElse: http://msdn.microsoft.com/en-us/library/ea1sssb2.aspx
      AndAlso: http://msdn.microsoft.com/en-us/library/cb8x3kfz.aspx

      Using FileIOPermissions With StreamWriter

      --The following exemplifies writing to a text file in a scenario where
      --permissions need to be temporarily altered:

      string tempPath = @"c:/file.txt";
      if (File.Exists(tempPath))
      {
      FileIOPermission fio =
      new FileIOPermission(FileIOPermissionAccess.Write, tempPath);
      fio.AddPathList(FileIOPermissionAccess.Write |
      FileIOPermissionAccess.Read, tempPath);

      fio.Demand(); --use the .Demand method to obtain permission

      StreamReader reader = new StreamReader(tempPath);
      string content = reader.ReadToEnd();
      reader.Close();

      for (int j = 0; j < stringToReplace.Length; j++)
      {
      content = Regex.Replace(content, stringToReplace[j],
      replacementString, RegexOptions.IgnoreCase);
      }
      StreamWriter writer = new StreamWriter(tempPath);
      writer.Write(content); writer.Close();
      }