.NET Tutorials, Forums, Interview Questions And Answers
Welcome :Guest
Sign In
Register
 
Win Surprise Gifts!!!
Congratulations!!!


Post New Web Links

Object cannot be cast from DBNull to other types

Posted By:      Posted Date: September 02, 2010    Points: 0   Category :ASP.Net
 
hello,i am using a web servicewrtitten in .net and i access the webservice from my wepApplication i get this error System.Web.Services.Protocols.SoapException: Server was unable to process request. ---> Object cannot be cast from DBNull to other types.my code is access webservice: protected void btnSave_Click(object sender, EventArgs e)        {            int intStatusCode;            dtProjectStatus = (DataTable)ViewState["dtProjectStatus"];            try            {                objService.Credentials = System.Net.CredentialCache.DefaultCredentials;                if(dtProjectStatus.Rows.Count>0)                {                  intStatusCode = objService.InsertTest(dtProjectStatus);                }   


View Complete Post


More Related Resource Links

Object cannot be cast from DBNull to other types.

  
Object cannot be cast from DBNull to other types. 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: Object cannot be cast from DBNull to other types.Source Error: Line 292: Line 293: If DataBinder.Eval(e.Row.DataItem, "Casette") IsNot Nothing Then Line 294: stcassette += Convert.ToDecimal(DataBinder.Eval(e.Row.DataItem, "Casette")) Line 295: End If Line 296:

Object cannot be cast from DBNull to other types

  
Case "System.Int32"                Return Convert.ToInt32(a) + Convert.ToInt32(b)Object cannot be cast from DBNull to other types

Object cannot be cast from DBNull to other types

  

Im receving a runtime error for this, and I've checked other posts for similar errors, but this error is different.  Does anybody have a clue?

Under Locals/ arparams/ for the first parameter "0" the more detail error reports:

"Data is Null, the method or property cannot cannot be called on null values"

Im rewriting this program in the 4.0 framework from 2.0, utilizing VisualStudio2010.

This ran fine previously without any erros in .NET 2.0. 

Here is the C# which collects the parameters and calls the stored proceedure. 

Here the first parameter strProjectID will be "" because this is a new project:

public static int SaveProject(string strProjectID, string strProjectName, string strProjectDesc, string strProjectNotes, string strProjectDate, string strProjectType)
        {
            // Update Project within hip_Project
            int newprojectid;
            SqlParameter[] arParms = new SqlParameter[6];

            arParms[0] = new SqlParameter("@pProjId", SqlDbType.Int, 1);
            if (strProjectID == "")
            {
                arParms[0].Value = DBNull.Value;
            }
            else
            {
                arParms[0].Value = strProjectID;
            }
            arParms[0].Direction = Parameter

Error: Object cannot be cast from DBNull to other types.

  

anyone can help me...

here's my error...

Exception Details: System.InvalidCastException: Object cannot be cast from DBNull to other types.

here's my code.

double totald = Convert.ToDouble(drReaderdeduc["TAMT"]);
totaldeduc.Text = String.Format("{0:N2}", totald);

the problem is the query output is null but i convert.todouble so got an error... what is the best solution if the record is null??? please help....


Unable to cast object of type 'System.DBNull' to type 'System.String'.

  

 I saw lots of post about this issue. but haven't got good solution for that yet. Basically, what I did is that: I have a table in SQL database and some of data fields allow null. I built Objectdatasource through dataset. When I built update page using dataset. It generate the following error before showing the update page correctly. It seems I have issue to retrieve the null value from the database through using objectdatasource through dataset. Any suggestions?

 

Xinguo

 

Error attached below:

Unable to cast object of type 'System.DBNull' to type 'System.String'.

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: Unable to cast object of type 'System.DBNull' to type 'System.String'.

Source Error:

Line 1178:            get {
Line 1179:                try {
Line 1180:                    return ((string)(this[this.tablemember.CurrentCityStateColumn]));
Line 1181:                

Unable to cast object of type 'System.Web.Mvc.ValueProviderResult' to type 'System.IConvertible'

  

Hello,
 Why am I getting this error on line:

               sp.Price = Convert.ToDecimal(collection.GetValue("Price"));

sp is :
  SPecials_Templates sp = new SPecials_Templates();

SPecials_Templates Defined:

    [MetadataType(typeof(SPecials_TemplatesMetaData))]
    public partial class SPecials_Templates
    {
        public class SPecials_TemplatesMetaData
        {

                [ScaffoldColumn(false)]
            public object Key { get; set; }
            [StringLength(50)]
            public object Template_Name { get; set; }
            [StringLength(12)]
            public object Headline { get; set; }
            [StringLength(12)]
    &nbs

Unable to Cast COM object

  
All, I receive this error when I tried to create SSIS project and add or create new SSIS package inside. Link to image as unable to insert here as directed in this link. Error:  Mircrosoft Visual Studio is unable to load this document: Unable to cast COM object of type 'Microsoft.SqlServer.Dts.Runtime.Wrapper.PackageNeutralClass' to interface type 'Microsoft.SqlServer.Dts.Runtime.Wrapper.IDTSPackageSigning100'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{A896D87C-D1B2-4FAE-9339-CFAFEFE617BE}' failed due to the following error: No such interface supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)) Possible Reason: 1. I was running on SQL Server 2008 R2 Evaluation Edition but I uninstall it and installed SQL Server 2008 Developer Edition with SP2 (CTP) first but when I see this problem so I uninstalled SP2 and now running on SQL Server 2008 with SP1. 2. I was also running on Visual Studio 2010 Professional Edition along with SQL 2008 R2 but I uninstall both same time when I installed SQL Server 2008 Dev edition. My OS is Windows XP SP3 and SQL Server 2008 SP1 as I mentioned.   I tried below steps but no luck  1. Registering DLL in this link. http://social.msdn.microsoft.com/forums/en-US/sqlintegrationservices/thread/7f5c9ae1-ecd3-4ead-98fd-2d074720e31d/ 2. Follow article

SP2010 Client Object Model: How to cast Field to FieldCalculated

  
Hello, I need to modify formula for existing field and can't do it because this code raise exception - (Cannot cast 'fld' (which has an actual type of 'Microsoft.SharePoint.Client.Field') to 'Microsoft.SharePoint.Client.FieldCalculated').   using (var clientContext = new ClientContext(@"http://Server")) { var web = clientContext.Web; var lst = web.Lists.GetByTitle("MyList"); <strong>var fld = (FieldCalculated)lst.Fields.GetByInternalNameOrTitle("Formula1");</strong> clientContext.Load(fld); clientContext.ExecuteQuery(); }   I can't use fld.SchemaXml modification by some reason. May be you can help me? Thank you.

"BDC Metadata Store is Currently Unavailable" when navigating to the External Content Types object i

  
After installing SharePoint 2010 Beta and Sharepoint Designer 2010, opening Designer and navigating to the External Content Types object results in the following error:"The Business Data Connectivity Metadata Store is currently unavailable."Anyone else having this experience?ThanksMark

Client Object Model : Transactional update of list and content types

  
I am using Silverlight client object model to code against Sharepoint. Essentially, what I want is that when a user clicks a button, An item needs to be added to a list and also a new content type has to be created. button1_click() { //1. Create an item in a list. //2.  Create a new content type. } Also this should be transactional:  only if item is added should the content type be added too, otherwise roll back both. (and vice-versa). My understanding of client object model is that we at the core we are talking to Sharepoint WCF services. So if I say, using(TransactionScope scope = new TransactionScope()) { ClientContext.ExecuteQueryAsync(); scope.Complete(); } can I assume that the updation will be transactional??

Unable to cast COM object of type 'System.__ComObject' to interface type 'IRowset'

  
I'm repairing a custom cube being fed off a Dynamics AX 2009 instance. This particular named query looks like this: SELECT CUSTTABLE.ACCOUNTNUM, CUSTTABLE.CASHDISC, CUSTTABLE.SHIPCARRIERBLINDSHIPMENT, CUSTTABLE.PARTYTYPE, CUSTTABLE.PARTYID, CUSTTABLE.SHIPCARRIERACCOUNTCODE, CUSTTABLE.PROJPRICEGROUP, CUSTTABLE.SYNCENTITYID, CUSTTABLE.SYNCVERSION, CUSTTABLE.MEMO, CUSTTABLE.SALESDISTRICTID, CUSTTABLE.CURRENCY, CUSTTABLE.SEGMENTID, CUSTTABLE.SUBSEGMENTID, CUSTTABLE.COMPANYCHAINID, CUSTTABLE.MAINCONTACTID, CUSTTABLE.IDENTIFICATIONNUMBER, CUSTTABLE.PARTYCOUNTRY, CUSTTABLE.PARTYSTATE, CUSTTABLE.SALESGROUP, CUSTTABLE.BLOCKED, CUSTTABLE.ONETIMECUSTOMER, CUSTTABLE.ACCOUNTSTATEMENT, CUSTTABLE.CREDITMAX, CUSTTABLE.MANDATORYCREDITLIMIT, CUSTTABLE.DIMENSION, CUSTTABLE.DIMENSION2_, CUSTTABLE.DIMENSION3_, CUSTTABLE.NAME, CUSTTABLE.VENDACCOUNT, CUSTTABLE.TELEX, CUSTTABLE.PRICEGROUP, CUSTTABLE.MULTILINEDISC, CUSTTABLE.ENDDISC, CUSTTABLE.VATNUM, CUSTTABLE.COUNTRYREGIONID, CUSTTABLE.INVENTLOCATION, CUSTTABLE.DLVTERM, CUSTTABLE.DLVMODE, CUSTTABLE.ADDRESS, CUSTTABLE.MARKUPGROUP, CUSTTABLE.MBSFIRSTNAME, CUSTTABLE.MBSLASTNAME, CUSTTABLE.MBSMESSAGETEXT, CUSTTABLE.MBSNOBOALLOWED, CUSTTABLE.MBSCOLLECTORCODE, CUSTTABLE.MBSDLVROUTESEQ, CUSTTABLE.MBSBOALLOCATIONPRIORITY, CUSTTABLE.MBSCUSTEMOTION, CUSTTABLE.MBSPRICEFLOOR, CUSTTABLE.MBSPRICECEILING, CU

Unable to cast object of type problem

  
hi I'm having a problem in this code: Public Function GetChannelList() As List(Of channel) Implements IChannelService.GetChannelList         Dim db As ChannelDataContext = New ChannelDataContext         Dim channelMatch = From channelRow In db.channels _                           Join parentChild In db.ChannelParentChildListings _                           On channelRow.channel_id Equals parentChild.parent_id _                           Order By channelRow.title Ascending _                           Select channelRow.channel_id, channelRow.title, parentChild.child,   parentChild.child_id           Return channelMatch    <-------- Error throw Unable to cast object of type 'System.Data.Linq.DataQuery`1[VB$AnonymousType_1`4[S

Unable to cast object of type 'System.Guid' to type 'System.String'.

  
protected void Button1_Click(object sender, EventArgs e) { using (BurnbetDataContext dc = new BurnbetDataContext()) { var q = (from c in dc.GetTable<tbl_Payment>() where c.ID == 5 select c).Single<tbl_Payment>(); dc.GetTable<tbl_Payment>().DeleteOnSubmit(q); dc.SubmitChanges(); } } }System.InvalidCastException was unhandled by user code  Message=Unable to cast object of type 'System.Guid' to type 'System.String'.  Source=System.Data.Linq  StackTrace:       at System.Data.Linq.SqlClient.SqlProvider.Execute(Expression query, QueryInfo queryInfo, IObjectReaderFactory factory, Object[] parentArgs, Object[] userArgs, ICompiledSubQuery[] subQueries, Object lastResult)       at System.Data.Linq.SqlClient.SqlProvider.ExecuteAll(Expression query, QueryInfo[] queryInfos, IObjectReaderFactory factory, Object[] userArguments, ICompiledSubQuery[] subQueries)       at System.Data.Linq.SqlClient.SqlProvider.System.Data.Linq.Provider.IProvider.Execute(Expression query)       at System.Data.Linq.DataQuery`1.System.Linq.IQueryProvider.Execute[S](Expression expression)&nb

Jax-WS and .Net client WSDL Object cast

  

Hello,

 

I'm currently developing a Jax-WS web service with a .NET client. I defined two objects in my web service like this:

 

public class Line(){

private Phrase[] phrase;

public Phrase(){

}

. . .

 

public class Phrase(){

private String[] words;

public Phrase(){}

. . .

}

 

I want to define a set of lines each one with a set of Phrases... and I use type Array of Phrases into an array of lines to do it. Similary, a Phrase is composed by a set of words. 

I've tested a web service method that returns an Object Lines with a java client and every thing went ok... but... When tested it on .net client the type  "Lines" is interpreted like "string [][]" instead of "Phrase []" ...and type Phrase is not recognised.

I've already tested this method by replacing String[] to String in class Phrase and it works on .net too... but I really needed to use it like String[].

Can anyone help with this please?

Thks a lot.

Gily


Is it possible to cast COM object to the custom interface?

  

I have following code which succesfully works using some COM wrapper library with all needed managed types for COM objects

mshtml.HTMLDocumentClass doc = (mshtml.HTMLDocumentClass)_webBrowser.Document;

mshtml.HTMLIFrameClass iframe = (doc).getElementById("SomeFrameName") as mshtml.HTMLIFrameClass;

if (string.Equals(iframe.readyState.ToString(), "complete", StringComparison.OrdinalIgnoreCase))

{

 // Do something

}

But I need to avoid this COM wrapper Micrososft.mshtml.dll and use custom interfaces for this reason, so please explain me how way can I work with COM objects with custom interfaces? How do I write them and avoid classes mshtml.HTMLDocumentClass and mshtml.HTMLIFrameClass?

Unable to cast COM Object - Exception

  

Hi everyone,

Ive been trying to develop a COM Client application, but without success. My goal is to create an application that can open reports in Cognos Impromptu. Ive got Cognos Impromptu installed on this machine and im using Visual Studio 2008 to develop the client.

I created my project as a consoleapplication in Visual Studio. Next, I added the Impromptu Client Reference via Project > Add Reference > COM. All works fine till now, Visual Studio creates my COM Wrapper dll and adds it to the bin/debug folder.

But when I trry to run my program, it gives me the following Exception:

Unable to cast COM object of type 'ImpromptuClient.ImpromptuApplicationClass' to
 interface type 'ImpromptuClient.IAppAuto'. This operation failed because the Qu
eryInterface call on the COM component for the interface with IID '{2F835754-FB4
F-11CF-8E5F-00401C60350D}' failed due to the following error: No such interface
supported (Exception from HRESULT: 0x80004002 (E_NOINTERFACE)).
Press any key to continue . . .

The code I use is as follows:

using System;
using System.Collections.Generic;
using System.Linq;
using System.

Unable to cast COM object error when calling COM from .NET C# worker thread

  

I'm having an issue calling a COM object function from .NET C# client program. The COM object is written in C++ unmanaged. The problem only appears when I'm calling from a worker thread, it works fine if I call it from the UI thread. This is the error:

Unable to cast COM object of type 'gvAgileFileReaderLib.gvAgileFileReaderClass' to interface type 'gvAgileFileReaderLib.IgvMpiRead'. This operation failed because the QueryInterface call on the COM component for the interface with IID '{616B5C39-C7FB-4C8C-85D4-27559DD83304}' failed due to the following error: Unspecified error (Exception from HRESULT: 0x80004005 (E_FAIL)).

I have tried the following methods but all of them fails:

1) Create the COM object on UI thread, and call its function via its interface (IgvMpiRead) in the worker thread

2) Create the COM object on the worker thread & access its function from worker thread

3) Tried with worker thread set to STA & MTA

I need to use the COM function is a worker thread to prevent a long processing from holding up my UI, but it just doesn't work when I try to call the COM function inside the worker thread.

The weird thing is that doing the same from a unmanaged C++ client works fine (I can create the com object on UI, and then call its function from worker thread). Is this problem caused by inter

Categories: 
ASP.NetWindows Application  .NET Framework  C#  VB.Net  ADO.Net  
Sql Server  SharePoint  Silverlight  Others  All   

Hall of Fame    Twitter   Terms of Service    Privacy Policy    Contact Us    Archives   Tell A Friend