dbnull

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

你离开我真会死。 提交于 2019-12-31 03:48:24
问题 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 procedure, minus some logic that I believe is not relevant: PROCEDURE CreateReport ( from_dt IN NVARCHAR2, to_dt IN NVARCHAR2, p_table_id IN NVARCHAR2, p_column_id IN

Which of IsDBNull and IsNull should be used?

此生再无相见时 提交于 2019-12-30 07:56:22
问题 If in VB.NET I have DataRow and I want to test whether a column value is Null , should I use: myDataRow.IsNull("Column1") OR IsDBNull(myDataRow("Column1")) 回答1: Short answer : use the first way, it is faster, because the first method uses a pre-computed result, while the second method needs to recompute it on the fly every time you call it. Long answer : (you need to read C# code to understand this part; MS supplies framework code in C#, but VB programmers should be able to get the general

How can I preempt the attempted assignment of DBNull to an int?

陌路散爱 提交于 2019-12-25 08:16:43
问题 The following code: foreach (DataRow fillRateDataRow in dtFillRateResults.Rows) { . . . var frbdbc = new FillRateByDistributorByCustomer { ShortName = fillRateDataRow["ShortName"].ToString(), Unit = fillRateDataRow["Unit"].ToString(), CustNumber = fillRateDataRow["Custno"].ToString(), MemberItemCode = fillRateDataRow["MemberItemCode"].ToString(), Qty = Convert.ToInt32(fillRateDataRow["Qty"]), QtyShipped = Convert.ToInt32(fillRateDataRow["QtyShipped"]), ShipVariance = fillRateDataRow[

Convert dbnull to string. Record dbnull.value in database instead of Nothing

一世执手 提交于 2019-12-24 07:26:29
问题 I have an insertRecord function in vb.net that uses a parameter query. If there is no error date given, I need to insert dbnull.value into the db instead of ""(Nothing). Dim strErrorDate2 As DateTime = Request.Form("dateOfErrorDatePicker2").ToString .Add(New SqlParameter("@ErrorDate2", If(strErrorDate2 <> Nothing, strErrorDate2.Date, DBNull.Value))) I keep getting conversion errors on dbnull to string. Originally it had it's own if/else block where I initialized the variable, but I couldn't

How do I set a field to DBNull in Entity Framework

送分小仙女□ 提交于 2019-12-23 07:57:50
问题 How do you set a field to DBNull in Entity Framework? The fields are strongly typed so you cannot set it equal to DBNull.Value and I did not find any method to set a field to DBNull. It seems like this is a necessary thing to do, but after much Google research I found nothing about it. I am trying to set a datetime field in Entity Framework using vb.net. This requires me to write myEntity.mydate = Nothing This does not set the field to null but instead sets it to the default date value which

Treating null field as zero for an update query

淺唱寂寞╮ 提交于 2019-12-23 04:47:07
问题 I'm using the SQL Express 2010 query builder. I need to be able to increment a field. In my behind code, I make a call such as tableAdapter.IncrementLikeCount(id); If I just use an increment, the like field can be null, so I want to either a. treat the null as zero in that field OR b. set to 1, if null, and increment otherwise. The most current thing I tried is option b with the following code in the query builder: UPDATE [dbo].[myTable] SET [LikeCount] = IIF(ISNULL([LikeCount]), 1, LikeCount

How can DBNull not equal DBNull

牧云@^-^@ 提交于 2019-12-22 04:48:08
问题 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 catching this and performing my alternate action but it does not? Can someone please shed some light for me. Thank you! 回答1: Try using Convert.IsDBNull method. 回答2:

Operator '??' cannot be applied to operands of type 'string' and 'System.DBNull'

主宰稳场 提交于 2019-12-22 01:26:38
问题 I have the following C# code: sqlCommand.Parameters.AddWithValue("@Parameter", table.Value ?? DBNull.Value); But it throws the following compilation error: Operator ?? cannot be applied to operands of type string and System.DBNull Why doesn't the compiler allow this syntax? 回答1: Both operands need to be object. Use explicit cast: (object)table.Value ?? DBNull.Value; 回答2: There is no automatic conversion between string and System.DBNull and so you need to specify the type you want explicitly

C# Database Access: DBNull vs null

跟風遠走 提交于 2019-12-21 03:36:33
问题 We have our own ORM we use here, and provide strongly typed wrappers for all of our db tables. We also allow weakly typed ad-hoc SQL to be executed, but these queries still go through the same class for getting values out of a data reader. In tweaking that class to work with Oracle, we've come across an interesting question. Is it better to use DBNull.Value, or null? Are there any benefits to using DBNull.Value? It seems more "correct" to use null, since we've separated ourselves from the DB

How to check for NULL in MySqlDataReader by the column's name?

左心房为你撑大大i 提交于 2019-12-20 17:33:04
问题 How can I check for a NULL value in an open MySqlDataReader ? The following doesn't work; it's always hitting the else : if (rdr.GetString("timeOut") == null) { queryResult.Egresstime = "Logged in"; } else { queryResult.Egresstime = rdr.GetString("timeOut"); } rdr.IsDbNull(int i) only accepts a column number, not name. 回答1: var ordinal = rdr.GetOrdinal("timeOut"); if(rdr.IsDBNull(ordinal)) { queryResult.Egresstime = "Logged in"; } else { queryResult.Egresstime = rdr.GetString(ordinal); }//if