Operator '*' is not defined for type 'DBNull' and type 'Decimal'.

 I am getting an error from the following line

 

  <asp:Label ID="Label1" runat="server" Text='<%# String.Format("{0:C}", Eval("ProductQty") * Eval("Price"))   %>' ></asp:Label>

 

I think I may need to convert/define the Variables but not quite sure how to do it.

 

Any help would be great.

0
drewsmith71
3/25/2009 12:28:09 PM
asp.net.getting-started 91979 articles. 4 followers. Follow

3 Replies
1953 Views

Similar Articles

[PageSpeed] 11

it's not a matter of converting...its the fact that the value from the DB is Null...

You'll have to wrap an IF check around it or change your query to return 0 instead of Null. If the field is a Qty you shouldn't be allowing Null anyway, change the field in the DB to not allow nulls and use 0 as a default.


0
Curt_C
3/25/2009 12:31:50 PM

 Thanks for the reply, I have implement as you have suggested.  I now get the following error:

 

The field 'Orders.ProductQty' cannot contain a Null value because the Required property for this field is set to True.  Enter a value in this field.

 The new figure entered does not seem to get passed over.  Here is my select and update script

 <asp:AccessDataSource ID="AccessDataSource1" runat="server"
            DataFile="~/App_Data/shop.mdb"
               DeleteCommand="DELETE FROM Orders WHERE (SessionID = ?) AND (ProductID = ?)"
           
            SelectCommand="SELECT Orders.SessionID, Orders.OrderID, Orders.CustomerID, Orders.ProductID, Orders.ProductQty, Orders.ItemTotal, Orders.[Date], Orders.Status, Products.ProductName, Products.Price FROM (Orders INNER JOIN Products ON Orders.ProductID = Products.ProductID) WHERE (Orders.SessionID = ?)"
                
              UpdateCommand="UPDATE Orders SET ProductQty = ? WHERE (ProductID = ?)">
            <SelectParameters>
                <asp:SessionParameter Name="SessionID" SessionField="SessionID" Type="String" />
            </SelectParameters>
            <DeleteParameters>
                <asp:SessionParameter Name="SessionDate" SessionField="SessionDate" />
            </DeleteParameters>
                 <UpdateParameters>
                <asp:Parameter Name="ProductID" Type="Int32" />
            </UpdateParameters>

 

Can you see anything obvious that I have done wrong?  

 

 

 

0
drewsmith71
3/25/2009 1:22:07 PM

Hmmm... change:
<asp:Parameter Name="ProductID" Type="Int32" />
to
<asp:Parameter Name="ProductID" Type="Int32" DefaultValue="0" />


0
Curt_C
3/25/2009 2:26:01 PM
Reply:

Similar Artilces:

Cast from type ''''DBNull'''' to type ''''String'''' is not valid.
How do I avoid getting this error: Cast from type ''''DBNull'''' to type ''''String'''' is not valid. I am trying to get values from the database into a form for updating using a Datareader, SQL is set to allow nulls for certain fields as they are not required but the only way I can get the form to display is by adding a space in SQL. Is there another way around this? Check if it is equal to DBNull.Value first and if it is, don't do the cast.Stanley Tan theSpoke Blog Where in the code does it need to go? I am using the following and it's the profile that isn't always requi...

''''''''''''''''''''
Name: haznen Email: haznenatyahoodotcom Product: Gran Paradiso Alpha 8 Summary: '''''''''''''''''''' Comments: '''''''''''''''''''''''''''''''''''' Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a1) Gecko/20061204 UGES/1.7.2.0 GranParadiso/3.0a1 From URL: http://www.mozilla.org/projects/granparadiso/ Note to readers: Hendrix gives...

Operator '>' is not defined for type 'DBNull' and type 'Integer'.
this is my code I don't get why I'm getting this error SubModel is a number :   Example : 823 If Ds.Tables(0).Rows(0).Item("SubModel") > 0 Then Dim crst As New DataSet SqlStr = "SELECT SubModelName FROM SubModel,AcesData WHERE AcesData.SubModel = SubModel.SubModelID and (SubModelID = ?)" Dim da2 As New Data.OleDb.OleDbDataAdapter(SqlStr, conn) da2.SelectCommand.Parameters.Add("?", Data.OleDb.OleDbType.VarChar).Value = Ds.Tables(0).Rows(0).Item("SubModel")...

Operator '=' is not defined for type 'Char' and type 'Boolean'.
Hello, In my application when i click the button i'm getting this " Operator '=' is not defined for type 'Char' and type 'Boolean'. " But when i test it locally there is no problem at all!!!! Please tell me why this error is occuring...Thanks SwapnaPlease click "mark as answer" if this post helped you. swapnasamsonvarkey: Hello, In my application when i click the button i'm getting this " Operator '=' is not defined for type 'Char' and type 'Boolean'. " But when i test it lo...

'''''
Name: mario Email: ramar17atfastwebnetdotit Product: Gran Paradiso Alpha 2 Summary: ''''' Comments: K: Browser Details: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9a2) Gecko/20070206 GranParadiso/3.0a2 ...

table_info('','','','%') cannot return any types
I was recently confirming table_info special cases and discovered the case for getting table_types cannot work. table_info('','','','%') should return a list of table types but it returns a list of empty strings instead: my @types = $h->tables('', '', '', '%'); print "all types:\n", join("xxx\n", @types), "\n"; # should output something like: # "dbo" # "INFORMATION_SCHEMA" # "sys" # and actually outputs: xxx xxx It seems to be down to the following ...

Operator '=' is not defined for type 'DBNull' and string
Hi,   This error occurs and im not sure why????? This is my code :   Dim Str_Staff As String = "SELECT * FROM sec_Staff"Dim cmd_Staff As New System.Data.SqlClient.SqlCommand(Str_Staff, myConnection_Staff) Dim ds_Staff As New DataSetDim da_Staff As New SqlClient.SqlDataAdapter(cmd_Staff) da_Staff.Fill(ds_Staff)   Dim i As Integer  For i = 0 To ds_Staff.Tables(0).Rows.Count - 1 If ds_Staff.Tables(0).Rows(i).Item("Email") = txtStep4_Email.Text ThenMsgBox("Email already used, please try again") rbtnStep3_SystemUser.SelectedValue =...

Cannot convert type 'type' to 'type'
I am learning all of this, so I am still fresh, so please bear with me :)I have a page that has some txtboxes in it, simple registration form, and I have a button that will save those txt boxes to the db. I am using:- I am using Visual Web Developer 2008 Express Edition- C# When I try to compile the project I get error: Cannot convert type 'System.Web.UI.WebControls' to 'String' This is content of my web.config    <profile> <properties> <add name="FirstName"/> <add name="LasttName"/>...

Cast from type 'DBNull' to type 'Decimal' is not valid
Hi, I want to add the shipping costs onto the OrderDetails.aspx which I'm bringing from a table called Shipping. I've added the ShipCost parameter to the GetOrderDetails function and the SPROC. However, sometimes the shipping cost is nothing (if the order is large enough), which is stored in the table as 0 and it seems to be this fact that is giving me the "Cast from type 'DBNull' to type 'Decimal' is not valid" error message. Any ideas how I work around this? Thanks in advance Hi Well I handle it in a couple of ways, being a self taught coder I am not sure if it's the recommended ...

Operator is not valid for type 'Single' and type 'DBNull'
Is there a function in the .NET Framework similar to the Nz function in Access? I'm looking for some way to return the default value for a DataRow Item if it is null (i.e. zero if numeric, zero-length string if defined as a string, false if boolean, etc.). Suggestions? you can use isnull function within the sql stmt..check out BOL for more info. hth***********************Dinakar NethiLife is short. Enjoy it.*********************** Is that a SQL Server function? I am currently dealing with Oracle and Access database retrievals. I know the IsNull function in the Framework will retur...

E2094 'operator+' not implemented in type 'XXX' for arguments of type 'int'
Okay I have a problem; I am trying to extend a string class that I wrote for a friend so I can use it another project I am working on. I have an error that makes absolutely no sense. Here is the code for the copy constructor: String(const String &str) // for copying into a new string object { Size = str.Size; Data = new char[Size+1]; for (int i = 0; i<Size; i++) Data[i] = str[i]; // recieving the following error on the above line: [BCC32 Error] Mystring.h(33): // E2094 'operator+' not implemented in type 'String' for arguments of typ...

'do' won't 'do' if '/'
Greetings to All from Au, Have a NetWare Perl 5.8.4 and wanted to tweak File\Spec\NW.pm to try and standardise on '/' separators. If I run a test script (t/uni/lower.t) with an unmodified NW.pm, it calls t/uni/case.pl, that, in case.pl, (when the path separators are '\'), the $file is '..\lib\unicore\To\Lower.pl' and the following code portion works, with $simple getting a returned table: sub casetest { my ($base, $spec, $func) = @_; my $file = File::Spec->catfile(File::Spec->catdir(File::Spec->updir, "lib", &qu...

I get Conversion from type 'DBNull' to type 'String' is not valid.
I get the following errors when I try and access certain pages.  It is caused by not populating all the text boxes with data and subsequent viewing causes these conversion errors.  Does any one else experience this?  How have you guys worked around this problem? Conversion from type 'DBNull' to type 'String' is not valid. Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. Exception Details: System.InvalidCastException: Conversion f...

'''
Name: L Lachowsky Email: e2brutus_10atyahoodotcom Product: Firefox Summary: ''' Comments: why duddn this surprise me... I change default server from IE to Mozilla, and then i get error messages. well, shud I decide to not get on my computer with Mozilla..or shud I risk security breeches with IE....hmmm at least i can get on the internet with IE Browser Details: Mozilla/5.0 (Windows; U; Windows NT 6.0; en-US; rv:1.9.0.5) Gecko/2008120122 Firefox/3.0.5 From URL: http://hendrix.mozilla.org/ Note to readers: Hendrix gives no expectation of a response to this fee...

Web resources about - Operator '*' is not defined for type 'DBNull' and type 'Decimal'. - asp.net.getting-started

Resources last updated: 1/7/2016 1:51:57 AM