dbnull

DBnull in Linq query causing problems

hi there i am doing a query thus: int numberInInterval = (from dsStatistics.J2RespondentRow item in jStats.J2Respondent where item.EndTime > dtIntervalLower && item.EndTime <= dtIntervalUpper select item).count(); there appear to be some dbnulls in the endtime column.. any way i can avoid these? ...

System.DBNull with data contract name not expected in WCF

I have an object array that I am passing to a WCF call that has DBNull.Value as one of the values. WCF is apparently choking on it because it doesn't know how to serialize it. Googling it only shows people who replaced the DBNull.Value with something else. Do I have to do that, or is there a way for me to have DBNull.Value on the clie...

Avoiding NULL object in HQL Query where clause

I have an entity which might have a parent entity. I want to run this query: select entity where entity.parent.id = 9 some of the entity does not have parents (entity.parent = null) and N HIBERNATE Fails to run this query (QueryException - Could not resolve property) How can I use HQL to get all the entities that has parents entities ...

How can DBNull not equal DBNull

I have the following line of code if (DBNull.Value.Equals(o) || o != null) where o is object o in row.ItemArray I keep getting an error of --> Xml type "List of xdt:untypedAtomic" does not support a conversion from Clr type "DBNull" to Clr type "String". What I don't understand is that when I step through my code this if should be...

cannot insert DBNULL value into sql server

Why i get this error? Object cannot be cast from DBNull to other types. when i inserted null value for a numeric datatype in sql server 2005 Here is my code, if (MeasurementTr.Visible == true) { materialIn.measurementId = Convert.ToInt64(DlMeasurement.SelectedValue.ToString()); } else { materialIn.me...

Is DBNull.Value required for nullable types as SqlCommandParameter.Value

Which approach is recommended: void Add(int? value) { command.Parameters.Add("@foo").Value = value; } or void Add(int? value) { command.Parameters.Add("@foo").Value = (object)value ?? DBNull.Value; } ...

Passing Null/empty string to Oracle stored procedure from asp.net

We have an ASP.NET web service that invokes a stored procedure on our DB (Oracle 11g). The problem is that the call to the procedure blows up every time an empty string is passed as one of the parameters. We're seeing an ORA-01084 error, which indicates to me that call is failing before the procedure is actually run. Here's the proced...

Filtering DBNull With LINQ

Why does the following query raise the error below for a row with a NULL value for barrel when I explicitly filter out those rows in the Where clause? Dim query = From row As dbDataSet.conformalRow In dbDataSet.Tables("conformal") _ Where Not IsDBNull(row.Cal) AndAlso tiCal_drop.Text = row.Cal _ AndAlso Not IsDBN...

LINQ Replace DBNull with Blank String

In this example, an error is raised if either row.FirstName or row.LastName are NULL. How do I rewrite the Select clause, to convert a DBNull value to a blank string ""? Dim query = From row As myDataSet.myDataRow in myDataSet.Tables("MyData") _ Select row.FirstName, row.LastName NOTE: Since the DataSet is strongly-typed....

Operand type clash: nvarchar is incompatible with image

I'm using a SQL Server 2008 stored procedure to create a new record with this syntax: cmd.Parameters.Add("@photo", DBNull.Value) cmd.ExecuteNonQuery() but the result is a: Operand type clash: nvarchar is incompatible with image Photo is not the only parameter but is the only image one, I am not passing a nvarchar but a null v...

Handle DBNull in C#

Is there a better/cleaner way to do this? int stockvalue = 0; if (!Convert.IsDBNull(reader["StockValue"])) stockvalue = (int)reader["StockValue"]; ...

ASP.Net check value with DBNULL

I have the following code foreach (DataRowView dr in Data) { if (dr == System.DBNull.Value) { nedID = 1; } } but i get the following error Operator == cannot be applied to operands of type System.Data.DataRowView and System.DBNull please can some one advice me on how...

Null safe way to get values from an IDataReader

Hi all, (LocalVariable)ABC.string(Name)= (Idatareader)datareader.GetString(0); this name value is coming from database.. what happening here is if this name value is null while reading it's throwing an exception? I am manually doing some if condition here. I don't want to write a manual condition to check all my variables.. I am doi...

why DataColumn AllowDbNull is true even if oracle db does not allow null

Hi. I have column SomeId in table SomeLink. When I look with tOra or Sql Plus Worksheet both state: tOra: Column name Data type Default Null Comment SOMEID INTEGER {null} NOT NULL {null} Sql Plus: SOMEID NOT NULL NUMBER(38) I have authored a method that's intended to give default values to all...

DBNull values on an ASP.NET MVC view

I am writing a simple ASP.NET MVC web app. At this point, I am just trying to display a strongly typed DataSet on the automatically generated view. However, some of the values in the DataSet are null and cause exceptions. I am wondering how this simple scenario is handled by others. It seems excessive to sanitize all the values in the ...

Issue with DBNull when using LINQ to DataSet

I've got the following LINQ Statement: Dim PSNum As Integer = 66 Dim InvSeq = (From invRecord In InvSeqDataSet.RptInvSeqDT.AsQueryable() _ Where IIf(invRecord.IsPack_NumNull(), False, invRecord.Pack_Num = PSNum) _ Select New With _ {.Inv = invRecord.Invoice_Num, .Seq = invRecord.Inv_Seq})...

Linq and DBNull - Getting error

Hi All, I'm getting an error when selecting from a rows.AsEnumerable(). I am using the following code... var rows = ds.Tables[0].AsEnumerable(); trafficData = rows.Select(row => new tdDataDC { CalculationCount = row.Field<Int64>("biCalculationCountSeqID") , Zone =...

Insert a NULL Date field into a Strongly Typed Dataset without getting a System.InvalidCastException

System.Data.StrongTypingException("The value for column 'CS_REPLY_DATE' in table 'CSAA_STATUS' is DBNull." I am using an Xmldataset .XSD connecting SQL Server 2005 tables, the dates I want to null out upon Initial insertion of a row into the table. The table date field allow nulls. I am using a strongly typed xsd table row and the ...

DBNull in non-empty cell when reading Excel file through OleDB

I use OleDB to read an Excel file. One of the columns has a "Common" format and contains both strings with letters and values consisting of numbers only. String values are retrieved without problem, but pure numerical values are retrieved as DBNull. How to solve? I use the following connection string to open Excel 2003 file (xls): "Pr...

Why can't I use '??' operand for System.DBNull value?

I have an Oracle data table fetching columns that be null. So I figure to keep the code nice and simple that I'd use the ?? operand. AlternatePhoneNumber is a string in my C# model. AlternatePhoneNumber = customer.AlternatePhoneNumber ?? "" However, even with that code I still get the error. System.InvalidCastException: Unable to cas...