null

C#: Alternative to GenericType == null

I need to check a generic object for null, or default(T). But I have a problem... Currently I have done it like this: if (typeof(T).IsValueType) { if(default(T).Equals(thing)) // Do something else // Do something else } else { if(thing == null) // Do something else // Do something else } But then I end up repea...

How can I print a literal 'null' for undefined values in Perl?

I am running a query 'describe table' and it returns value of 'null' for the 'default' column. However, when I try to print the value from database to an HTML table it is not printing 'null'. It is just always blank. This is how I am storing the data from database: @nulls = (); while (($null) = $sth1->fetchrow_array) { push...

What's the best way to write "nulls" to SQL database when presenting options in combobox?

Hi Guys, I'm writing a front end to a database, presenting options as comboboxes. And I need to be able to return nulls to the database. I have a solution at the moment which involves 'fudging' a record into the query to populate the Datatable, then detecting the selection and hard coding null into my update statement if this item has...

What is the purpose of null?

I am in a compilers class and we are tasked with creating our own language, from scratch. Currently our dilemma is whether to include a 'null' type or not. What purpose does null provide? Some of our team is arguing that it is not strictly necessary, while others are pro-null just for the extra flexibility it can provide. Do you have an...

Why does my repeater keep crashing on Eval(NULL) values?

<asp:Repeater ID="rptLessons" runat="server"> <ItemTemplate> <tr> <td><%#Eval("fullname")%></td> <td><%#isCompleted(Eval("totallessons"), Eval("completedlessons"), Eval("totalNumAvail"), Eval("totalNumCorrect"))%></td> <td><%#FormatPercent(Eval("totalnumcorrect") / Eval("totalNumAvail"))%>...

How do I make this SQL statement return empty strings instead of NULLS?

LastAccessed=(select max(modifydate) from scormtrackings WHERE bundleid=@bundleid and userid=u.userid), CompletedLessons=(select Value from scormtrackings WHERE bundleid=@bundleid and userid=u.userid AND param='vegas2.progress'), TotalLessons=100, TotalNumAvail=100, TotalNumCorrect=(SELECT Value FROM scormtrackings WHERE bundleid=@bun...

Why don't we have two nulls?

I've often wondered why languages with a null representing "no value" don't differentiate between the passive "I don't know what the value is" and the more assertive "There is no value.". There have been several cases where I'd have liked to differentiate between the two (especially when working with user-input and databases). I imagin...

Is there a basic Java Set implementation that does not permit nulls?

The API for the Java Set interface states: For example, some implementations prohibit null elements, and some have restrictions on the types of their elements I am looking for a basic Set implementation that does not require ordering (as ArrayList provides for the List interface) and that does not permit null. TreeSet, HashSet, and...

C#: Comparing with null

Are these equivalent: if (null==myobject) { //do something } and if (myobject==null) { //do something } or will they produce different code? ...

Java List with blank allowed

Hello, This is probably really simple but I really could not word it properly on Google. See, I have a ArrayList that keeps the info for each thread. Each thread has it's own ID. So, at the beggining: myList.add(theIdOfTheThread, new InfoForTheThread()); //Add new thread info at index theIdOfTheThread And when I want info: myList.get...

ExecuteXmlReader and null Resultset Throws TargetInvocationException

I'm calling a stored procedure on a SQL Server 2005 database which returns an XML resultset. Sometimes it will return an null resultset becuase there are not rows to return. When this happens athe ExecuteXmlReader method throws a TargetInvocationException. This seems to be a known issue (see: http://social.msdn.microsoft.com/Forums/en-US...

Dropdownlist value not getting set from SelectList passed to view in ViewData

I am trying to populate a dropdownlist of office locations(text) and addresses (value) When viewing my page source in my browser after displaying the page I can see that the select (dropdownlist) option values are all "". Here is my code. I am using a LinqToSql data context call to get my data for the SelectList. In the debugger I can s...

Is there a varargs null check function in Java or Apache Commons?

I've got four variables and I want to check if any one of them is null. I can do if (null == a || null == b || null == c || null == d) { ... } but what I really want is if (anyNull(a, b, c, d)) { ... } but I don't want to write it myself. Does this function exist in any common Java library? I checked Commons Lang and didn't...

Is there any reason to check for a NULL pointer before deleting ?

I see some legacy code checking for null before deleting the pointer. as like below if(NULL != pSomeObject)//any reason for checking for null { delete pSomeObject; pSomeObject = NULL;//any reason for assigning null } my compiler is vc6 pre-standard one though. ...

NULL pointer with boost::shared_ptr?

What's the equivalent to the following: std::vector<Foo*> vec; vec.push_back(NULL); when dealing with boost::shared_ptr? Is it the following code? std::vector< boost::shared_ptr<Foo> > vec; vec.push_back(boost::shared_ptr<Foo>()); Note: I may push back a lot of such objects. Should I declare a global static nullPtr object somewhere...

In PHP, what is the differences between NULL and setting a string to equal 2 single quotes.

I used to set things like this when I wanted blank values. $blankVar = ''; Then after some months, I decided this looked better and had a clearer intent. $blankVar = null; This worked without hiccup for a while, but recently with a PDO prepared statements I ran into a problem. Binding a value to null made the query fail, whilst bin...

Handling null references when using eg Linq-To-Xml

Is there a better/shorter way to handle (lots of) null references, for example when I'm using LinqToXML. I wrote this extention for XElement that handles it quite nicely, but maybe there is another way? And what about the function name? "And" isn't really descriptive. public static class XmlExtentions { public static T And<T>(th...

SQL Server - Performance/Size Drawbacks of Null Columns

I'm working on a table design that could involve many NULL values in about 10 fields maybe 75% of the time the fields would be unused. I just generated some fake data (a million records) and could not sense any impact on SQL Server 2005. Size difference was in the KB. Performance - no measurable difference after adding an index to the 3...

nullable types: best way to check for null or zero in c#

i'm working on a project where i find i'm checking for the following in many, many places: if(item.Rate == 0 || item.Rate == null) { } more as a curiousity than anything, what's the best way to check for both cases? I've added a helper method which is: public static bool nz(object obj) { var parsedInt = 0; var parsed = int.Try...

Getting rid of null/empty string values in a C# array

I have a program where an array gets its data using string.Split(char[] delimiter). (using ';' as delimiter.) Some of the values, though, are null. I.e. the string has parts where there is no data so it does something like this: 1 ;2 ; ; 3; This leads to my array having null values. How do I get rid of them? ...