Search Results

Search found 56 results on 3 pages for 'murdoch'.

Page 3/3 | < Previous Page | 1 2 3 

  • Name for method that takes a string value and returns DBNull.Value || string

    - by David Murdoch
    I got tired of writing the following code: /* Commenting out irrelevant parts public string MiddleName; public void Save(){ SqlCommand = new SqlCommand(); // blah blah...boring INSERT statement with params etc go here. */ if(MiddleName==null){ myCmd.Parameters.Add("@MiddleName", DBNull.Value); } else{ myCmd.Parameters.Add("@MiddleName", MiddleName); } /* // more boring code to save to DB. }*/ So, I wrote this: public static object DBNullValueorStringIfNotNull(string value) { object o; if (value == null) { o = DBNull.Value; } else { o = value; } return o; } // which would be called like: myCmd.Parameters.Add("@MiddleName", DBNullValueorStringIfNotNull(MiddleName)); If this is a good way to go about doing this then what would you suggest as the method name? DBNullValueorStringIfNotNull is a bit verbose and confusing. I'm also open to ways to alleviate this problem entirely. I'd LOVE to do this: myCmd.Parameters.Add("@MiddleName", MiddleName==null ? DBNull.Value : MiddleName); but that won't work. I've got C# 3.5 and SQL Server 2005 at my disposal if it matters.

    Read the article

  • What is this: main:for(...){...} doing?

    - by David Murdoch
    I pulled up the NWmatcher source code for some light morning reading and noticed this odd bit of code I'd never seen in javascript before: main:for(/*irrelevant loop stuff*/){/*...*/} This snippet can be found in the compileGroup method on line 441 (nwmatcher-1.1.1) return new Function('c,s,d,h', 'var k,e,r,n,C,N,T,X=0,x=0;main:for(k=0,r=[];e=N=c[k];k++){' + SKIP_COMMENTS + source + '}return r;' ); Now I figured out what main: is doing on my own. If you have a loop within a loop and want to skip to the next iteration of the outer loop (without completing the inner OR the outer loop) you can execute continue main. Example: // This is obviously not the optimal way to find primes... function getPrimes(max) { var primes = [2], //seed sqrt = Math.sqrt, i = 3, j, s; outer: for (; i <= max; s = sqrt(i += 2)) { j = 3; while (j <= s) { if (i % j === 0) { // if we get here j += 2 and primes.push(i) are // not executed for the current iteration of i continue outer; } j += 2; } primes.push(i); } return primes; } What is this called? Are there any browsers that don't support it? Are there other uses for it other than continue?

    Read the article

  • Has jQuery core development been slowing down?

    - by David Murdoch
    So, I regularly head over to jQuery's Commit History on GitHub just to read through the new code committed to jQuery core. But there hasn't been anything new committed since April 24th. I've already read through jQuery core a few times and I'm pretty familiar with it which is why I like reading the commits. I just like to see what changed, why it was changed, etc. Why has there been a slow down in jQuery commits on GitHub? Anyone else have some recommendations for where I can go to view good javascript code being developed? My motive for reading jQuery's commit history is similar to the reasons I browse through accepted answers here on stackoverflow - to learn from people smarter than me. With that said, I am interested in the answer to this questions title, but I am more interested in finding a substitute to reading the jQuery commits.

    Read the article

  • Get Item from Collection by unique ID

    - by David Murdoch
    I have a collection of Contacts that inherits from CollectionBase: public class ContactCollection : CollectionBase{ //... } each contact in the collection has a unique ID: public class Contact{ public int ContactID{ get; private set; } //... } I think what I would like to do is something like the following: // get the contact by their unique [Contact]ID Contact myPerson = Contact.GetContactById(15); // get all contacts for the customer ContactCollection contacts = customer.GetContacts(); // replaces the contact in the collection with the // myPerson contact with the same ContactID. contacts.ReplaceAt(myPerson); // saves the changes to the contacts and the customer // customer.Save(); There is probably a better way...if so, please suggest it.

    Read the article

  • Server RAID 5 failed...all I have left is my compiled website

    - by David Murdoch
    Yesterday, 2 of the 3 drives in my dev server's RAID 5 decided to die on me (with no warning). I've come to grips with the fact that my data is most likely lost unless I shell out some major bucks for professional data-resortoration. People, don't be an idiot like me and treat your RAID as a data backup! Luckily I published the site about 4 hours before my files went bye-bye. Is there any way to run some [magical] program to restore my compiled site to their original files? Also: I develop on one machine with the files stored on the server...is there some visual studio 2010 web cache on my local machine (the one that didn't crash) that I may be able to use?

    Read the article

< Previous Page | 1 2 3