CodeVerge.Net Beta


   Explore    Item Entry    Members      Register  Login  
NEWSGROUP
.NET
Algorithms-Data Structures
Asp.Net
C Plus Plus
CSharp
Database
HTML
Javascript
Linq
Other
Regular Expressions
VB.Net
XML

Free Download:




Zone: > NEWSGROUP > Asp.Net Forum > visual_studio.visual_studio_2005 Tags:
Item Type: NewsGroup Date Entered: 12/11/2007 3:49:36 PM Date Modified: Subscribers: 0 Subscribe Alert
Rate It:
(NR, 0)
XPoints: N/A Replies: 2 Views: 32 Favorited: 0 Favorite
Can Reply:  No Members Can Edit: No Online: Yes
3 Items, 1 Pages 1 |< << Go >> >|
chas28
Asp.Net User
Error with NULL using EXECUTE SCALAR12/11/2007 3:49:36 PM

0/0

I keep getting an error message when I try to place the result of an execute scalar command into a text box.  The msg is:"conversion from 'DBNull' to type 'String' is not valid"

The code I am using is:

 

Dim con as OLEDBConnection

con =NewOleDB connection("Provider = MIcrosoft.JetOLEDB.4.0, Data Source = "c:\caps.mdb")

Dim cmd As OLEDBCommand

cmd= NewOLEDBCommand("Select Product from [Inventory Table] Where [Customer ID] = " & grid View1.SelectdValue

texBox1.Text = cmd.ExecuteScalar

 

The code works fine as long as there is a value for the Product.  However if the value in the database is NULL I get an error message: :"conversion from 'DBNull' to type 'String' is not valid". How do I wok around this?

Chas28

 

zeemalik78
Asp.Net User
Re: Error with NULL using EXECUTE SCALAR12/11/2007 4:18:26 PM

0/0

You need to first check the returning value of the query that if it is null then you don't need to set the text box text because its text property require an empty or non empty string not the Null value.

Try this:

if not cmd.ExecuteScalar = DBNull.Value then

 texBox1.Text = cmd.ExecuteScalar

End If

 

Don't forget to click "Mark as Answer" on the post that helped you.
This earns you a point.

 

Zeeshan Malik
http://zeemalik.wordpress.com

chas28
Asp.Net User
Re: Error with NULL using EXECUTE SCALAR12/11/2007 9:42:14 PM

0/0

Sorry, but "if not cmd.ExecuteScalar = DBNull.Value" does not work. I get the error message :

'= is not defined for system.data.OLEDbCommand' and 'system.DBNull''

but thanks for trying.

Chas28

3 Items, 1 Pages 1 |< << Go >> >|


Free Download:

Books:
Beginning C# 2005 Databases Authors: Karli Watson, Pages: 501, Published: 2006
MCAD/MCSD Training Guide (70-310): Developing XML Web Services and Server Components with Visual Basic. Net and the . Net Framework Authors: Mike Gunderloy, Ed Tittel, Pages: 1024, Published: 2003
ADO.NET 3.5 Cookbook Authors: Bill Hamilton, Pages: 980, Published: 2008
Programming Perl: There's More Than One Way To Do It Authors: Larry Wall, Tom Christiansen, Jon Orwant, Pages: 1067, Published: 2000
Programming the Perl DBI: Database Programming with Perl Authors: Alligator Descartes, Tim Bunce, Pages: 346, Published: 2000
Reference Manual for the Ada Programming Language Authors: United States Dept. of Defense, American National Standards Institute, American National Standards Institute, Pages: 330, Published: 1983
A Complete Guide to DB2 Universal Database: IBM's Object-relational Database System Authors: Donald Dean Chamberlin, Pages: 795, Published: 1998
Perl in a Nutshell: A Desktop Quick Reference Authors: Ellen Siever, Stephen Spainhour, Nathan Patwardhan, Pages: 654, Published: 1999
MySQL Cookbook: Solutions and Examples for MySQL Database Developers. Authors: Paul DuBois, Pages: 992, Published: 2003
Beginning ASP.NET 1.1 Databases: From Novice to Professional Authors: Damien Foggon, Daniel Maharry, Pages: 600, Published: 2004

Web:
Error with NULL using EXECUTE SCALAR - ASP.NET Forums Re: Error with NULL using EXECUTE SCALAR. 12-11-2007, 11:18 AM. Contact ... Re: Error with NULL using EXECUTE SCALAR. 12-11-2007, 4:42 PM. Contact ...
ExecuteScalar problem for null values - .NET C# 3 kk NULL I'm using executescalar to get the updated values from the table ... When execute the above query it is throwing error as "object ...
Handling null values returned via SQL ExecuteScalar() query ... I suppose I could just trap that error, but I'd rather design it so no ... IIRC - ExecuteScalar returns null if no value is returned, and ...
How to check execute scalar is returning null values - Dev Shed hi i m using executescalar for retrieving the employeename . But against the Querry Empname is empty. therefore it i giving an error object reference not ...
MySQL :: ExecuteScalar just seems to return null?!?! Jan 9, 2008 ... Net :: ExecuteScalar just seems to return null? ... have written I get no error but the value that is returned from "ExecuteScalar" is null. ...
ExecuteScalar returns null - MS SQL ExecuteScalar returns null. Question posted by: js (Guest) on October 24th, 2006 10:55 PM. I am using the following C# code and T-SQL to get ...
ExecuteScalar not functioning on server - Stack Overflow Sep 30, 2008 ... null). The procedure fails on object lookupResult = cmd.ExecuteScalar(); with this error:. Event Type: Error Event Source: App Log Event ...
ExecuteScalar gets Specified cast is not valid error - ASP.NET Forums I was getting an error also on the cast to an integer when using ExecuteScalar. I needed to return the count from a table using something like this to make ...
ODP.NET - Handling Nulls and ExecuteScalar If the ExecuteScalar returns a double value, it would never be a problem. What if it returns a NULL? The following is the error you would receive: ...
[RESOLVED] help with Oracle ExecuteScalar - VBForums ToString ())); //Error occurs in (int)OraCmd.ExecuteScalar() if ((int)OraCmd. ExecuteScalar() != null || txtAddUsername. ...




Search This Site:










database deployment from sql express 2005 to regular 2005

installation problems on 3.0.11

always have to login twice :(

asp to asp.net

how to convert .aspx page to .html page

unhandled exception

anyone decode this?

security exception after uninstallaing .net v1.1

problem with membership database

access provider

can regularexpression do ?

user via windows authentication

help changing code to use a veriable for a file name

help on how to access another module's settings

web.sitemap

post approval sucks!

can i drag the values between two web parts

javascript in htmlfeed module causes dnn errors, etc

how to use default masterpage?

texteditor user control question

i just deleted all my skins....and now i get this error: an unhandled error has occurred.

storing credit card details on a database using encryption...

read the emails from my outlook express

obtaining value of selected node

upgrade pain

web part not registered as safe - namespace

100,000! whoo hoo!

treeview ontreenodepopulate not assigned

upgrading users from dnn1.0 to dnn 3.1

is the codebehinds compiled into bin dll

 
All Times Are GMT