Cast from type 'DBNull' to type 'Integer' is not valid. #2

Hello every one.

I have a store database procedure that give me back this error: "Cast from type 'DBNull' to type 'Integer' is not valid"

 How can I get where is exactly the error....???



9/19/2006 2:47:04 PM 91979 articles. 4 followers. Follow

2 Replies

Similar Articles

[PageSpeed] 50

This seems to be a .NET exception. Post the code how you pass values to the parameters and execute the stored procedure
Welcome to my SQL/ASPNET forum for Chinese
9/21/2006 2:32:02 AM


In the procedure you can use the following coe for the null field 

Isnull(Fieldname,"value when the field is null") 

Hope this helps


Vikram's Blog - Vikram's look at and its related technology


Please mark the answer if it helped you
9/22/2006 2:55:41 AM

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...

Cast from type 'DBNull' to type 'Integer' is not valid
any suggestions ??Sunny NAGIProper Preparation Prevents Poor PerformanceDont forget to click "Mark as Answer" on the post that helped you. Means you can't cast from type DBNull to type Integer (well, obviously). Just check if it is DBNull and if it is, don't cast it.Stanley Tan theSpoke Blog thanks mate !! I fixed it in sql querySunny NAGIProper Preparation Prevents Poor PerformanceDont forget to click "Mark as Answer" on the post that helped you....

Cast from type 'DBNull' to type 'Integer' is not valid.
I tried string and integer, still does not like the cast.. Any suggestions Dim intPrefixID As Integer = IIf(cboPrefix.SelectedItem.Value = "NONE SELECTED", System.DBNull.Value, cboPrefix.SelectedItem.Value) You can't do that. Instead, if the SelectedItem.Value is NONE SELECTED, set the intPrefixID to null. Then, in your data access code, check to see if it is null. If so, assign the parameter the DBNull.Value. Otherwise, assign it the SelectedItem.Value.Darrell Norton, MVPDarrell Norton's BlogPlease mark this post as answered if it helped you! I'm confuse...

Cast from type 'DBNull' to type 'Integer' is not valid.
Can someone please help me with this exception: I get it when I update a post in the Discussion module. The weird thing is: it updates the line in the database correctly AND gives this error! Now I wonder what did I do wrong... Server Error in '/Portal' Application. -------------------------------------------------------------------------------- Cast from type 'DBNull' to type 'Integer' 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 a...

Cast from type 'DBNull' to type 'String' is not valid #2
G'day, Puzzled by this. The error occurs on the field "Mobile" yet its format is exactly the same as the other fields. In otherwords I can remove the line of code dealing with "Mobile" and it will function. Can anyone explain? The error is : Cast from type 'DBNull' to type 'String' is not valid. <%#ifPresent("Phone:",Container.DataItem("Phone"))%> <%#ifPresent("Fax:",Container.DataItem("Fax"))%> <%#ifPresent("Mobile:",Container.DataItem("Mobile"))%> <%#ifPre...

Cast from type 'DBNull' to type 'String' is not valid. #2
i have an login page which use e-mail address and password to login , once the system comfirm this is valid login it get customer details and in my login page i have the following code Dim loginsystem As onlineshop.Customers = New onlineshop.Customers() Dim customerId As String = loginsystem.customer_login(login.email_address, login.password) If customerId <> "" Then Dim customerDetails As onlineshop.customer_Detail = loginsystem.Get_Customer_Details(customerid) and at the onlineshop.customer_detail function i have the following ...

Cast from type 'DBNull' to type 'String' is not valid. #2
I think this is a bug, the database of Products are allowed to have "Null" Value, but when you do have one, the store is crashed with subjected message, I have found a solution to use View to change the Null value into something when run the SQL store procedure, but I don't know if is there anyway from "Class" side to solve it. Always check for Null before trying to convert the value to a string or assign to a text or label. Try this: If Not(IsDbNull(drProducts("foo"))) Then ...insert your code to display here... End If mix it up! www.devalch...

Error : Cast from type 'DBNull' to type 'Integer' is not valid
Hi all,         I have beign figure the error for days but still cant figure out what's went wrong and no idea how to solve this error : Cast from type 'DBNull' to type 'Integer' is not valid. This is what i want to do :1.Display the number of item added into the shopping cart retrieved from the database. (workable)2.If there is qty eg. 2 in the shopping cart,it will display 2 items.(workable)3.But when i remove all the items in the shopping cart,this error : Cast from type 'DBNull' to type 'Integer' is not valid occured4. Anyone knows what code should...

Cast from type 'DBNull' to type 'String' is not valid
Hi,  I have an old website and old database (SQL 2000).  I add new column "ImageURL' to database, so all data (several thousand items) are "NULL" (actually is dbNull) under this column.  In searchResult.aspx page, inside the datagrid, I add a colummn call "Image" <code> <asp:datagrid id="dgSearchResult" runat="server"><Columns><asp:TemplateColumn HeaderText="Image" ItemStyle-Width="55px" ItemStyle-HorizontalAlign=Center> <ItemTemplate> <asp:Image ID=ThumbImage Wi...

Cast from type 'DBNull' to type 'String' is not valid.
On the viewproduct page if any of the db fields referenced in the SP are empty you get the above error, the error originates in the productsDB.vb file as follows myProductDetails.ModelNumber = CStr(parameterModelNumber.Value) myProductDetails.ModelName = CStr(parameterModelName.Value) myProductDetails.ProductImage = CStr(parameterProductImage.Value).Trim() myProductDetails.UnitCost = CType(parameterUnitCost.Value, Decimal) myProductDetails.Description = CStr(parameterDescription.Value).Trim() OK I can make ...

Cast from type 'DBNull' to type 'String' is not valid
I REALLY need some help, so here goes. The following function does work as long as the "mail" field in the database isn't NULL. As you can see I have tried a couple of ways to check for a NULL value but none of them seem to work. What's supposed to happen is the function checks to see whether or not a user has an email address in the database. If so, then the email address gets returned, if no email address then I need something back from the function so I can go about another way to get the info to the user. Public Function GetReqByEmail(ByVal reqby As String) As String...

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 ...

Cast from type 'DBNull' to type 'String' is not valid
 Hi all,Sorry to be posting here on what is probably a common enough error but I am at my wits end with this one. Quite simply I call an Update stored procedure in my code, passing in a number of paramaters. However, when I try to run the code, the following exception is thrown:Cast from type 'DBNull' to type 'String' is not validI'm really not sure what the problem is here. I have tried hardcoding values for the string values with no success also, as well as using the IsNothing function, but no joy there eitherI would really appreciate someones help as I spent 2 hou...

Cast from type 'DBNull' to type 'String' is not valid.
Hi, I have a page with several's a "change your account" page. One of the parameters is presented as a label instead since it is not changed ON THIS PAGE. It needs to be NULL when the account is created and entered later. But when the page loads, I get the above error. The account row is loaded from a business object LoadFromId(). How can I load the page even though this label data is NULL to start with? relevent code below. <asp:Label ID="lblDDAccount" Runat="server"></asp:Label>------If currentUser.DDAccount = "" Then       &...

Web resources about - Cast from type 'DBNull' to type 'Integer' is not valid. #2 -

Resources last updated: 12/13/2015 2:09:45 AM