Linq Expression Returning Null Rather Than Empty Set
Nov 18, 2010
I am finding this weird issue. When I do this > activities.Where(Function(a) (Not a.IsDeleted And a.ParentId = 100) It returns an in-memory query & when I try opening it up, it throws a object not set exception. This only happens when there were no items which satisfied the condition. Shouldn't it be returning an empty set? When there are items satisfying the condition, then it returns a list & works all good.
This must've have been asked before but I couldn't locate it. In a mixed code project (VB and C#) we were debugging some old Visual Basic code where a statement as follows could be found:
If Request.Params("xxx") <> "" Then 'do something
I considered this a bug as Request.Params could be null, in which case the statement would've become false which wasn't the idea. So I thought. I just found out, -- probably for the tenth time and I will keep forgetting -- that the following two statements are not equal, while Nothing in VB should be equal to null in C# (thought I):
if(String.Empty == null) // always false If String.Empty = Nothing Then ' always true
Should I dismiss this as a typical Microsoft backward compatibility effort, or should I consider this a huge error in the VB.NET compiler? Does anybody know the Microsoftean opinion on this oddity?
Public Sub checkemail() sqlcheckemail = "select Email from WEBUSER where Email='" + TBEmail.Text + "'" Dim dscheckemail As New DataSet
[Code]....
if u see the one that i've commented is the one i already googled at tested...so now if the email address exist in the db..everything works wonderful..but if it doesn't exist the code should process the one that does not satisfy the first if statement...but now i'm getting the result as "There is something" eventhough the email does not exist in the db...
This may seem like a dumb question, but how do you set a default date for the datetimepicker or set today's date as default in the table?
For some reason the control (every instance I've inserted so far) returns a null value when I try to update rows without selecting or entering a specific date while the program is running. The date columns are required, and in at least one case I need the date to automatically return today's date.
In the properties I have chosen "values" for today's date, past dates, even future dates, but I keep getting the following error:
A first chance exception of type 'System.Data.NoNullAllowedException' occurred in System.Data.dll
When I review the details, VS tells me that the date column in question does not allow nulls. If I select a date while running the program, I don't get this error, so it seems like the default value is not getting set.
This is probably a really basic (no pun intended) question, but I can't seem to find an answer anywhere.Why does the result of func1 return False and func2 returns True? On every other test I have done, integer 1 is converted to boolean true and 0 to false. Works ok if I just set rtnValue to 1 or 0.
I have this function correctly linked in an external .js file...
function SubmitAge(age, UpdatePanelID, HiddenAgeID) { $get(HiddenAgeID).value = age; __doPostBack(UpdatePanelID); }
and am calling it like this from an onClick of an a href="#" ... html tag (tags removed, please scroll right as stackoverflow has the greatest difficulty in displaying simple content, 7th display related edit,
[Code]...
Why on earth is HiddenAgeId, clearly passed just like UpdatePanelID, is returning an "Undefined identifier Error"??? its perplexed me to the point where i have no room to move! have i missed something guys?edit: Update: turns out it works perfectly (as it should) when i load it up in FireFox, but has the resulting error in Internet Explorer, this is not a browser compatibility issue, it should also work in IE, but it doesn't!
Having trouble importing a value from a .csv file to a .csv file. This this done because data needs to be massaged and the data file renamed. This is a user interface. Do not want to have the user touch the .csv in any way except upload to the application so the applicaiton can do manipulation. Either way here is the issue.
There is a column in the original .csv file that contains a zip code. The first row of the .csv has a value of 17003 in the zip code column. In the second row of the .csv the zip code column has a value of 11746-9984. The value in the zip code column from the second row always comes back as a Null value. My guess is that the OleDbDataAdapter is defining some kind of Schema. Again, the first row containing the zip code column probably insists the value must be numeric. When the data table field is established it probably gets defined as numeric. If that is true and the second row of the .csv zip code column is not numeric that must cause the zip code value to be Null.[code]...
I am still a newbie with VB. If I return a number the if statement works fine, with opening the new form and updating it as needed. Id the if statement returns a Null from the database it crashes.
I have this function correctly linked in an external .js file...
function SubmitAge(age, UpdatePanelID, HiddenAgeID) { $get(HiddenAgeID).value = age; __doPostBack(UpdatePanelID); }
and am calling it like this from an onClick of an a href="#" ... html tag (tags removed, please scroll right as stackoverflow has the greatest difficulty in displaying simple content, 7th display related edit, thanks stackoverflow)
a href="#" onclick="SubmitAge(24, 'ctl00_MainContent_arFrom_upAgeRange', 'MainContent_arFrom_HiddenAge')" runat="server" 24 /a
yet, i am getting this error, and its being called on the first line of the SubmitAge function (line with $get(HiddenAgeID)... etc...)
Error:Microsoft JScript runtime error: 'null' is null or not an object
i've copied and pasted my WATCH windows in visual studio .net (vs2010 beta 2 using vb.net & c#) while the execution breaks inside teh SubmitAge .js function...
age 53 Number UpdatePanelID "ctl00_MainContent_arTo_upAgeRange" String HiddenAgeID Undefined identifier Error
Why on earth is HiddenAgeId, clearly passed just like UpdatePanelID, is returning an "Undefined identifier Error"???
edit: Update: turns out it works perfectly (as it should) when i load it up in FireFox, but has the resulting error in Internet Explorer, this is not a browser compatibility issue, it should also work in IE, but it doesn't!
In my VB.NET application when I try to get the image location using picturebox.ImageLocation (path), it is returning null. I have to use that path string in filestream's parameter to open it. Since it is returning null, I couldn't open the file (image) in filestream. The following error is coming: "Path cannot be null"
This is my code: Dim path As String = Picturebox1.ImageLocation Dim filestrm As FileStream = New FileStream(path, FileMode.Open) Dim arry(filestrm.Length - 1) As Byte filestrm.Read(arry, 0, filestrm.Length)
My code seems to behave a way I don't understand. Sometimes it returns null as expected and sometimes it returns a value when its supposed to be null. How can someone explain this? Here is the code that selects from access and displays the result in a messagebox:
cmd5.Connection = cnn cmd5.CommandText = "SELECT receipt_num " & _ "FROM brought_coffee, farmer where crop_year= " & yr & " and " & _ "brought_date=#" & dtt & "# and farmer_centre='" & ctr & _
i have a date control on form (vb.net) and by default its value is current date. i want to make its value to null or empty so that no date is shown and user choose from the drop down date calendar.
Dim re As New Regex("((?<field>[^"", ]+)|""(?<field>([^""]|"""")+)"")((?<rowbreak>, | | |$)|,)") [Code] ..... Now it puts all the data in the correct columns but there's just a comma in the empty columns.
I am trying to call an external C++ function using VB.NET (answers in C# are fine, I can convert back) which returns a list of device names. This comes in the form of a pointer to a null-terminated array of null-terminated char arrays (correct me if I've misunderstood what I'm dealing with) with a function signature:
long GetNames(char*** names)
Most of the answers to similar questions I've found have involved something more like:
long GetNames(char** names, int length)
It appears from what I've read that I need to give it an IntPtr but I'm uncertain as to how this should be initialized, and in my case I don't know the length of the array. At the moment, in the VB module, I have:
<DllImport("MyExternal.dll", CallingConvention:=CallingConvention.Cdecl)> _ Function GetNames(ByRef names as IntPtr) As UInteger End Function
I've tried calling the function by passing an IntPtr initialized as IntPtr.Zero or using Marshall.AllocHGlobal, but I always get an AccessViolationException.
Any ideas on how I should be calling this function and how I get the return value into a managed string array would be greatly appreciated.
EDIT: I've found a sample function call in native C as follows:
I'm deserializing some XML from an old application into an object in my current application. The old XML often has empty elements (<SomeElement />) which are currently deserialized as empty strings (""). I agree that this is the most appropriate behaviour, but it is a minor irritant; I'd rather they were deserialized as Nothing or ideally ignored - the effect would be the same. Is there a means of ignoring these elements? Or can I have them deserialized as Nothing?
The code below works fine as long as there are values within an XML node (For example the <CPU>Intel</CPU> node below) but it throws an Exception error when the node value is blank/null whatever as in the example node <Monitor> </Monitor>.t's ok if the node value is blank, I just want to check for it and not throw an exception error.This question uses the following XML snippet below: Note: The tag <Monitor></Monitor> has no value in it.
I constantly find myself having to do code similar to the following.[code]Is there anyway to check for both on a single line? When i'm checking a condition for a great number of answers, I sometimes end up with conditionals 6-sets deep. If i check for null first, an error still pops up, even though VB shouldn't check since the first condition failed. i.e.[code]
How can I change the following code to write to the database null instead of empty strings?
Public Sub SetChangeRequest(ByVal referenceLeaseID As Integer, _ ByVal referenceCustomerID As Integer, _ Optional ByVal custUnitNum As Object = Nothing, _
I have the following code that checks if the value in a cell contains a nummeric value.
Private Sub dgvOrderRegel_CellValidating(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellValidatingEventArgs) Handles dgvOrderRegel.CellValidating Select Case e.ColumnIndex Case 4 'Aantal If Not IsNumeric(e.FormattedValue) Then
I'm using FileHelper to generate object's property. Here is an example of one property:
<FieldOptional(), _ FieldTrim(TrimMode.Both)> _ <FieldNullValue(GetType(String), " ")> _ Public StoreNo As String
As you can see the StoreNo will either have a value or " ", one of the business policy is to check if the StoreNo is empty or nothing if the object's StoreNo is empty or null then the record will not create.
I though about creating an HasValue Function in the class to check the StoreNo and other properties in the object but I feel like it is a hack.
Public Function HasValue() As Boolean Dim _HasValue As Boolean = True If StringHelper.IsNullOrBlank(Me.StoreNo) Then
[Code]....
I don't think this approach is an ideal solution. what if the StoreNo is remove or change to something else. What's the best approach to check object's property?
I have a form and stored procedure that inserts the data from the form. It works fine except that if a field isn't filled in it doesn't insert a NULL into SQL it inserts "".
I've tried a few different ways but none seem to insert NULL, the one below still inserts "", can anyone point me in the right direction?
Here is the required part of the code, if you require more just let me know.
Dim rdr As SqlDataReader Dim cmdInsert As SqlCommand = New SqlCommand() cmdInsert.CommandText = "spPersonalDetailsInsert"
[Code].....
So if I enter nothing into address1 field it should write NULL to screen but it always writes NOT NULL. What does an empty form field equal? in classic ASP it was always "".
I have a couple of textfields in a Windows form. One of these textfields is allowed to be NULL. When I enter a value for every field, it is all inserted, no problem. When I leave the field (txtGewicht) blank, I can't seem to be able to insert NULL in Access Database.
If Double.TryParse(txtGewicht.Text, 0) Then klant.Gewicht = Double.Parse(txtGewicht.Text) Else
[Code]....
This is what I get:
"Cannot set column 'Gewicht' to NULL, please use DBNull instead"
So I changed 'Nothing' to DBNull.value, but it then tells me that System.DBNull cannot be converted to type Double.
I have a large one dimensional array that is called ArrayHold which is populated at runtime. I run a loop to scan through the array to find out which elements need to be removed based on a few parameters. This all works great, now I am left with two arrays. The original one and a new one which contains the locations of the elements to be removed.
Original Array: ("A")("B")("C")("D")("E")("F")("G")("H")
Second Array with index/count of elements that needs to be removed: ("0")("3")("5")("7")
End result should be preferably not in a new array but a "ReDim" of the original array:("B")("C")("E")("G")
What would be the simplest way to achieve this? I could run a loop to make all the elements that need to be removed "0" or ""? Would there be an easy way of resizing and array by dropping/removing all the white space or empty elements?