Thursday, February 18, 2010

Change Windows Password and SQL Instance Windows Authentication Credentials

I ran across this issue today when I changed my network password and then all of the sudden I couldn't get my SQL Instance running nor could I log in to SQL Manager with my windows authentication because it was using cached credentials from my previous password. Fortunately it was a simple fix.

Open Services and find the instance service (Right click Computer and goto manage) then right click and find properties. I simply supplied my new password and viola. Hopefully this helps someone else.

Friday, January 15, 2010

Javascript Open Child Window and print

 Open a child window, load with dhtml/arbitrary html, or url and then have it open the print dialog. I tested in IE8,Fire Fox 3.5.7,Chrome 3.0.195.38, Safari (4 public beta) for windows.

After running into some frustration that the print() wasn't being fired I ran across a post where the child window must be reloaded...viola...thank you internet.
 <html>
   <head>
      <script type="text/javascript" language="javascript">
         function printdiv()
{
    try
    {
               var childWindow = window.open("about:blank", "_blank", "height=800,left=100,top=100,width=800,resize=yes,toolbar=yes,titlebar=0,status=0,menubar=yes,location= no,scrollbars=1"); 
        var headstr = "<html><head><title>Print Window</title></head><body>";
                var footstr = "</body>";
                var printData = document.getElementById("divPrint").innerHTML;
                if (printData == null || printData == "")                                       
                    printData = "Oops, there appears to be no data.";              
                childWindow.document.write(headstr + printData + footstr);
                childWindow.location.reload(false);     
                childWindow.print();
           }
           catch (e)
           {
              alert("It appears that your browser doesn't support print features." + e);
           }
           finally
           {
              return false;
           }
      }
      </script>
   </head>

   <body>
      <form id="form1" runat="server">
          <button onclick="return printdiv();" >Open child window and print</button> 
          <div id="divPrint" style="display:none;">I love life...but not like that</div>
      </form>
   </body>
</html>  

Friday, April 24, 2009

Arithmetic Parser

I was shocked to learn that the process of applying arithmetic order of operations was already available to you in .Net. Sure it can be done through a slightly obscure fashion, but the results are fantastic. Better yet nearly only 4 lines of code...amazing.


string expression = "(2.2 + .8) * 10";
DataTable dataTable = new DataTable();
dataTable.Columns.Add("col1", typeof(double), expression);
dataTable.Rows.Add(new object[] { });
MessageBox.Show(Convert.ToString(dataTable.Rows[0][0]));

Outputs 30....What a time saver.

Wednesday, February 25, 2009

Converting List types in C#

I was searching earlier and saw that many people's solution to this issue is implementing a for loop. No need with >= c#2.0 List has a very handy ConvertAll method.

I have a quick example of the awesome power in 2 lines of code.Convert List<int> into a List<string> or List<int> into an array of strings which I needed to join a list of ids.

List<int> myList = new List<int>(){ 101,202,332,343};
string sIdList = string.Join(",", myList.ConvertAll<string>(delegate(int i){return i.ToString();}).ToArray());

sIdList output is "101,202,332,343"

I hope this helps someone else.

Monday, February 2, 2009

SQL Server 2008 Edit Top 200 Rows

I thought this feature was fixed, but glad to see that you can override very easily in the SQL Object Browser interface. Tools - Options - Sql Server Object Explorer

C# DataTable with Custom Objects

Came across this little tidbit to allowing custom object types in a .net DataTable. Issue being that if you don't set the property, you get the string value of the object.

DataTable dt = new DataTable();
DataColumn dcMyObject = new DataColumn("MyObject");
dcMyObject.DataType = typeof("MyNameSpace.MyClass");
dt.Columns.Add(dcMyObject);

Thursday, January 29, 2009

Bank of Karma

This blog is to try and give back to the web with what I take.