My datetime field getting errors

I retrieve records using stored procedure into DataRow called "row".  Now I getting error about DBNull and the field seems to contain {} values.

 Server Error in '/Web' Application.


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 103:            decimal  Reorderlevel = decimal.Parse(row["P_ReorderLevel"].ToString());
Line 104:            string  Warehouseno = row["P_WareHouseNo"].ToString();
Line 105:             DateTime  Modifieddate = Convert.ToDateTime(row["P_ModifiedDate"]);
Line 106:            string Memo = row["P_Memo"].ToString();
Line 107:            string Desc = row["P_Desc"].ToString();


Source File: C:\IList_WareHouse_Solution\DataObjects\SqlServer\SqlServerProductDao.cs    Line: 105

Here is what my code is like in retrieving the data.  I have to return Modifieddate in the return statement to display record in DetailsView.  If I test for dbnull, what do I set the Modifieddate when its value is {}.

 

sql.Append("usp_SelectProduct");

SqlParameter[] p = new SqlParameter[1];

p[0] = new SqlParameter("@P_Productid", SqlDbType.Int);

p[0].Value = ProductID;

DataRow row = Db.GetDataRow(sql.ToString(), p);

int productid = int.Parse(row["P_ProductID"].ToString());

string Productname = row["P_ProductName"].ToString();

.............

string Warehouseno = row["P_WareHouseNo"].ToString();

DateTime Modifieddate = Convert.ToDateTime(row["P_ModifiedDate"]);

.................

Product product;

return product = new Product(productid, Productname, Qtyperunit, Unitprice, Unitsinstock, Unitsonorder, Reorderlevel, Warehouseno, Modifieddate, Memo, Desc);

thanks

Nick

0
nnnnnpatel
10/23/2006 8:36:10 PM
asp.net.object-datasource 16182 articles. 0 followers. Follow

1 Replies
518 Views

Similar Articles

[PageSpeed] 21

Emm~ It depends on your Product class implementation to see what to set for the Modifieddate value when facing null value. You shall know it yourself~
 
你好! Just FYI o_O
0
Gordon
10/27/2006 4:09:06 AM
Reply:

Similar Artilces:

I get this error when i use object datasource
This is the first time i am using object datasource , I am getting an error saying Procedure or Function 'GeteGroupExceptionalByResource' expects parameter '@ResourceName', which was not supplied.   I tried several times to solve the error , but i couldnt able to , I tried debugging several times,but couldnt able to solve the error .For many attemps i get the same above error ,pls advice me how to solve this error   Thanks You have to pass the value for the paramneter @ResourceName through your coding or in Properties window depanding upon your project PROC...

Added and changed field names in table contacts, get object reference error
Hi, I have searched through the forum and most question about this error occurs when people are trying to connect for the first time and don't have there settings correct. I have been working on a site for a long time, still locally. Today I decided to add a couple of fields to the contacts table for more info, I also changed the field names on some of the existing fields. I also changed the stored procedures and all the information necessary in the files in the "/desktopModules/Contacts" folder, including procedures, function and design. The object reference not set to an i...

Getting error in Net::SFTP with get function
------=_Part_7028_3315294.1193837808284 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Hi All, I have the following code as part of my program; print "---=========> $file, $localFile\n"; $sftp -> get( $file, $localFile ) || warn("errrrr0rrrrr _---> $!".$sftp->status."\n");^M Even though it has downloaded the file properly, it is giving the following message: ---=========> /trading/tiscrdenhlist10310000.txt.old, /export/home/crdadm/rajeev/tiscrdenhlist103...

error "Failed to get datetime data" using dw.net 1.0.1
Hello, My situation: I have a vs2005 project with dw.net version 1.0.1 (build 5502), database is asa10. When my regional settings are Dutch(Belgium) I have no problems at all. When the settings are Italian(Italy) I get a "Failed to get datetime" error when I retrieve when my data contains dates. When the date fields are not filled in then I do not get the error. A date of '2008-1-1 08:00:00' also gives errors. When I try to retrieve the same data in the datawindow painter I also get no error. Can anyone help me? Greetings, Mich=E8le DW.net 2.5 is now th...

Compating DateTime field from sql table to DateTime Object
Hi. I have a SQL query that suppose to compare a given DateTime object to a datetime type coloumn : SELECT COUNT(*) FROM [QuestionnairesData] WHERE [SQClientUsername] = '" + Profile.UserName + "' AND [FillingDate] > " + Report.GetLastProductionReportDate(sqClient.SQCLIENTID)  the problem i get is on the last part of the select query. the DateTime object Report.GetLastProductionReportDate(sqClient.SQCLIENTID) gives me : 2/14/2007 15:49:04 PM and when i delete the time part it works well but i need to check for both date and time in this case. there is some issues with DateTime o...

Error in OLE object's getting error
All, I have a PowerBuilder6.5 applications open an ole connection and run MS-Word and run MS-Word's Macro. Inside the Macro, I have an error trapping statement to give an error msg on all errors. On the PB side, I have created an ole object based on oleobject and has an event error. My problem is ob PB, the ole object's error event gets trigger, but on MS-Word, I see no error prompt at all. How is it possible? How does PB know MS-Word has error when MS-word itself reports nothing? How does PB get trigger? Thanks DB ...

Error in OLE object's getting error #2
All, I have a PowerBuilder6.5 applications open an ole connection and run MS-Word and run MS-Word's Macro. Inside the Macro, I have an error trapping statement to give an error msg on all errors. On the PB side, I have created an ole object based on oleobject and has an event error. My problem is ob PB, the ole object's error event gets trigger, but on MS-Word, I see no error prompt at all. How is it possible? How does PB know MS-Word has error when MS-word itself reports nothing? How does PB get trigger? Thanks DB ...

.NET Datetime object
I want to know everything about the DateTime Class ,I mean where can I find the information about this class . You may find some help from here.This posting is provided "AS IS" with no warranties, and confers no rights. Do below link helps you for your need! It will have all the info what you want! http://msdn.microsoft.com/library/default.asp?url=/library/en-us/cpref/html/frlrfsystemdatetimeclasstopic.asp Hope it helps!Sreedharhttp://www.w3coder.orgweblog http://weblogs.asp.net/skoganti...

I just started getting this error in vs2005b2: Object reference not set to an instance of an object.
All I have to do is create a new web project, create a master page, then create a normal web page.  I read a posting someplace else that suggested removing the user profile solves this problem. So, if that is the case, how to I remove my user profile?  Peter Kellnerhttp://73rdstreet.com and blogging athttp://PeterKellner.netMVP, ASP.NET Can you post more information about the error? (Line number, source code found at file/line of error, etc.)? Also, you can try running the same page in the browser directly, and see what error ASP.NET gives you. Thanks,Shanku Niyogi Th...

Converting classic to .NET 2 code, and .NET gets an error back from ADS?
 For future-proofing, our Internal Phone Directory is being moved onto our AD servers, and obviously we're using LDAP for queries.To get the phoneboook queries working, I adapted the current classic ASP code to use LDAP, and that works fine. However, we're wanting to move these pages to .NET, and that's where the problem comes in. Using the same basic logic from the Classic code (90% of its unchanged) to produce an LDAP query, I get the error  155 Unknown error (0x80005000)This is using the same website, and so the same credentials  - unless aspx pages run und...

Getting Error: Object reference not set to an instance of an object when working with Drop Down Lists
Dear Forum, I am trying to make a web form that will open up a database record, and let me edit that record.  It works fine until I want to load one of the columns HeadlinerName/HeadlinerID into a drop down list.  The text boxes work fine. It is just the DDL's that are giving me trouble. I get the error: Object reference not set to an instance of an object.  to this line of code: HeadlinerNameDDL.SelectedItem.Value = HeadlinerID  Any ideas what I can do to make this work?Any guidance you can offer me would be greatly appreciated.Jeff Wood, Bois...

used a c#.net to vb.net converter and am now getting a syntax error.
ok I used a cool utility at http://www.kamalpatel.net/ConvertCSharp2VB.aspx to convert some c#.net to vb.net and it spit out a bunch of code which almost works but I am getting a syntax error on this line Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) I tried it that way and also like Imports (StreamReader sr = Shadows Function)() As StreamReader(objResponse.GetResponseStream()) but either way gave the same error Compiler Error Message: BC30035: Syntax error. Source Error: Line 26: Line ...

When creating an word object, i get an error : Access is denied: Error Code -- 80070005
Hi, guys,i am creating a web site, one thing i have to do is to create a report on the fly and display it in MS Office Word.i am referencing the following article:http://www.codeproject.com/aspnet/wordapplication.aspAnd used the following code:Word.ApplicationClass wordApp = new Word.ApplicationClass();however, an error occurs when creating object wordApp:Retrieving the COM class factory for component with CLSID {000209FF-0000-0000-C000-000000000046} failed due to the following error: 80070005 Exception Details: System.UnauthorizedAccessException: Retrieving the COM class factory for co...

when deploying website I get "Object Reference not set to an instance of an object" error
I have developed a website in Visual Studio 2003.  The site runs fine locally on my PC but when I compile it in debug mode and copy it to a (remote) staging server I get the above message: Error in: http://stageservername/sso/login.aspxError Message: Object reference not set to an instance of an object.Stack Trace:at Travel.login.btnLogin_Click(Object sender, ImageClickEventArgs e) in c:\inetpub\wwwroot\localprojectaddress\travel\sso\login.aspx.cs:line 292 at           System.Web.UI.WebCo...

Web resources about - My datetime field getting errors - asp.net.object-datasource

Is there a JQuery plugin to convert UTC datetimes to local user timezone?
If I have a tag: <span class="utctime">2010-01-01 11:30 PM</span> I would like a jquery script or plug in to convert every utctime ...


Targetprocess 3.7.3: Epic unit for Bug/Story cards, new DateTime functions in Webhook plugin
Webhook plugin supports new DateTime functions AddDays(DateTime date, int days) – Returns a new date with the number of days added. The number ...

Common Pitfalls when working with DateTime’s
In .NET, the DateTime structure provides us wonderful functionality, but this seemingly simple structure can cause a lot of headaches if you ...

Parsing Twitter Date format to .Net DateTime
Recently when I needed to parse the twitter datetime format into a .Net DateTime I found this post on the web showing how to do it. However, ...

C Sharp (programming language) - Wikipedia, the free encyclopedia
(pronounced see sharp ) is a multi-paradigm programming language encompassing strong typing , imperative , declarative , functional , generic ...

1753 - Wikipedia, the free encyclopedia
Language: English Afrikaans አማርኛ العربية Aragonés Asturianu Aymar aru Azərbaycanca বাংলা Bân-lâm-gú Basa Banyumasan Беларуская ‪Беларуская (тарашкевіца)‬ ...

Coded Smorgasbord: Schizophrenic Haiku Comments and More
... writes Malcom StandardResponse UnSubscribeNewsletterUserAccount( string opTinGUID,string email, string sellingRegion, string source, DateTime ...

Limburg.be - Welkom op de site van de provincie Limburg - Welkom_op_de_site_van_de_provincie_Limburg
visit wonen werken leven ontspannen infopunt home op trefwoord contactpersonen wegwijs sitemap print deze pagina Je bent hier: limburg.be Contact ...

Simples Ideias. Por Nando Vieira.
Simples Ideias Siga-me no Twitter Junho/2012 Usando o Vagrant como ambiente de desenvolvimento no Windows http://simplesideias.com.br/usando ...

Resources last updated: 12/8/2015 1:57:11 PM