Roy Ashbrook

let go or be dragged
posts - 197, comments - 29, trackbacks - 8

June 2010 Entries

Showing status in c# loop using the modulus operator (%)

I needed to take some records in one file, do some stuff with the record, then put the results in another file. The 'do stuff' part was taking a bit longer than I thought it would so I wanted to see status. This sample illustrates taking 1000 records from a source file, uppercasing each line, putting it in another file, and letting us know every 100 lines. using(TextWriter tw = new StreamWriter(@"uppercase.txt",false)) {     int i = 0;     var q = File.ReadAllLines(@"lowercase.txt").Take(1000);     foreach(var v in q)     {         tw.WriteLine("{0}", v.ToUpper()); //print status on every 100th record         if ((i % 100) == 0) Console.WriteLine("{0}/{1} processed", i.ToString(),q.Count().ToString());         i++;     }     Console.WriteLine("{0}/{1} processed", q.Count(),q.Count().ToString()); }

posted @ Friday, June 25, 2010 9:08 AM | Feedback (0) |

ROW_NUMBER() AND PIVOT AND TEST DATA, OH MY!

So the other day I got the following question about reporting on some log data: The data being loaded is a bunch of machine log files. (E.g. MachineName Status Timestamp) The status is a simple Start or Stop. My question is can I use Datediff between sequential records to determine elapsed time between start and stop? I know this would work if the start and stop data were in the same record and I believe this will work between sequential records but I'm fuzzy on what's best and putting it into action Below is the end result of my answer....

posted @ Tuesday, June 22, 2010 12:00 AM | Feedback (0) |

Careful with your LINQ joins (WHERE IN TSQL with LINQ)

So today I needed to cross reference some stuff in a text file with some stuff in a db. No big deal. Had about 200 unique values to lookup a few pieces of info out of a larger table in a db. The target table had about a half million rows in it, but was indexed on this particular column I needed to lookup on so it seemed like it should be no big deal. I have found myself using LINQPad more and more for little ad-hoc stuff like this. Anyway, I was prepared to do something similar to this:...

posted @ Tuesday, June 8, 2010 6:20 PM | Feedback (0) | Filed Under [ DEV ]

Some EF Weirdness (LINQ to Entities does not recognize the method 'System.String ToString()')

So I was writing a really simple EF web method today. It just checked for the presence of two values in a table and would return true or false. [WebMethod] public bool weird(long l, string s) { using (someEntities db = new someEntities()) return db.things.SingleOrDefault(x => x.s == s && x.l == l.ToString()) != null; }  The code above gives me the following error: System.NotSupportedException: LINQ to Entities does not recognize the method 'System.String ToString()' method, and this method cannot be translated into a store expression This...

posted @ Friday, June 4, 2010 10:10 AM | Feedback (0) |

SQLCE on IIS

So this apparently isn't supported, but I just thought I would jot down some notes about how to get it working. It is really not that hard as long as you don't mind installing SQLCE on your IIS server. I am still working on how to distribute the SQLCE files with the application.  I have a very small set of data that is mostly read and so I wanted to just dump it on a web server and not have a sql server. SQLCE seemed perfect for this although apparently that's not a use it's currently designed for. Here are some...

posted @ Thursday, June 3, 2010 11:21 AM | Feedback (0) |

How to automatically play and loop a youtube video

I like to do this every once in a while when I am practicing a song or if I just want to listen to the same song over and over again. But I always forget how and have to look it up. So now I can just look back here. First you need the video ID, this is in the of any normal youtube video you are watching. For example: http://www.youtube.com/watch?v=Ed49S2nyBD0 The ID from this video is Ed49S2nyBD0. Just replace the that ID in the url below and form the URL the same as below and autoplay and loop till your heart...

posted @ Wednesday, June 2, 2010 3:37 PM | Feedback (0) |

How to setup blogging to subtext from word2007

Specifically, how to set this up for OUR blog =P Thanks to Dennis and this article for the info. These are steps for someone that doesn't already have a blog setup in word 2007. I will assume if you do, you already know enough and the settings/info from this will be enough. Click new document and choose 'Blog Post'. The following screen will come up. Click 'Register Now'.  You select 'Other' from the Blog drop down and click Next.  This is where the fact that we have multiple blogs appears to differ from the instructions in the link above. I filled out the...

posted @ Wednesday, June 2, 2010 11:00 AM | Feedback (0) |

Test from Word 2007 =D

With a picture, no less. <edited?>  

posted @ Wednesday, June 2, 2010 10:42 AM | Feedback (0) |

Powered by: