473,396 Members | 1,758 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

DBNull problem

Hi all and thanks to those who respond to this.
I have a data maintenance form which I am using to update data in my
database. In the update routine I use the following code;

ssql = "UPDATE Email_Usage SET [date] = @Date," & _
"pagesgenerated =
@PagesGenerated," & _
"pagesemailed =
@PagesEmailed," & _
"customersemailed =
@CustomersEmailed " & _
"WHERE id = @ID"
Dim params(4) As SqlClient.SqlParameter
params(0) = New SqlClient.SqlParameter("@Date", dtDate)
params(1) = New SqlClient.SqlParameter("@PagesGenerated",
dr("pagesgenerated"))
params(2) = New SqlClient.SqlParameter("@PagesEmailed",
dr("pagesemailed"))
params(3) = New SqlClient.SqlParameter("@CustomersEmailed",
dr("customersemailed"))
params(4) = New SqlClient.SqlParameter("@ID", dr("id"))

dr is a DataRow

All is well when I supply values for fields on the form. If the user
does not enter a value for Customers Emailed, I write DBNull.Value into
dr instead. The problem is that when I execute the query I get an error
that I must declare the variable @CustomersEmailed. Why will it not
accept DBNull.Value ?

Jul 6 '06 #1
3 1484
Is it possible that you need a space after the last parameter is
assigned?

Currently your third parameter is 'customersemailed' but there is no
space before your WHERE statement. Could this mean that when the final
sql query is constructed, there is no space between the third parameter
and the WHERE clause?

I only responded because I support LFC as well. :)

Liverpool fan wrote:
Hi all and thanks to those who respond to this.
I have a data maintenance form which I am using to update data in my
database. In the update routine I use the following code;

ssql = "UPDATE Email_Usage SET [date] = @Date," & _
"pagesgenerated =
@PagesGenerated," & _
"pagesemailed =
@PagesEmailed," & _
"customersemailed =
@CustomersEmailed " & _
"WHERE id = @ID"
Dim params(4) As SqlClient.SqlParameter
params(0) = New SqlClient.SqlParameter("@Date", dtDate)
params(1) = New SqlClient.SqlParameter("@PagesGenerated",
dr("pagesgenerated"))
params(2) = New SqlClient.SqlParameter("@PagesEmailed",
dr("pagesemailed"))
params(3) = New SqlClient.SqlParameter("@CustomersEmailed",
dr("customersemailed"))
params(4) = New SqlClient.SqlParameter("@ID", dr("id"))

dr is a DataRow

All is well when I supply values for fields on the form. If the user
does not enter a value for Customers Emailed, I write DBNull.Value into
dr instead. The problem is that when I execute the query I get an error
that I must declare the variable @CustomersEmailed. Why will it not
accept DBNull.Value ?
Jul 6 '06 #2
This gets more and more curious.

If I change DBNull.Value to SQLInt32.Null then it works, however I get
a casting error when trying to insert the latter into the field in the
data row. The column in the data row will accept DBNull.Value but not
SQLInt32.Null, and the parameters accept the latter as a value but not
the former. Any ideas?

Thanks for the post Steven. If you look closely you will see there is a
space after the last parameter.

Do you think Stevie G sgould be the new England captain then. I do. He
plays with the kind of passion that the team is lacking I think.

Jul 6 '06 #3
Sorry I didn't see the space. Wearing my glasses this time I promise.
Not sure about your curious findings. But in knowing that now can you
you organise to place the correct null value where required? We use a
custom data layer and in the background it uses the SqlInt32.Null
syntax for adding null parameters. But when wanting a value in a
datarow to be null, it simply doesn't assign a value.. . (not assigning
a null value, just don't assign anything). Not sure if this helps your
cause.

RE: England
At least Gerrard would never break down and cry like Becks. He has
captain experience, but why would you want to captain a big group of
girls? He would be a good captain but I don't think he should do it.
Coming from Australia, I can be objective about England's international
team. I think captaining is not England's biggest problem, its the
manager. Luckily he's gone now. I mean, WHO subs on a non-penalty taker
in the 120th minute of the game!!!!

Jul 6 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

19
by: jim | last post by:
This line of code returns error 13, cast from 'DBNull' to type 'String' is not valid If IsDBNull(Clinics.Clinics.Item(A).Workphone) The <other code End I Clinics.Clinics is a dataset that...
5
by: DraguVaso | last post by:
Hi, Something I don't understand about a Typed DataSet: When a value in the DataSet is DBNull, it throws this error: "Cannot get value because it is DBNull". But aren't Typed DataSets...
7
by: | last post by:
Source Error: Line 173: sData(rownumber - 1, lcnt) = WhatCol.Value Line 174: End IF Line 175: If (sData(rownumber, lcnt) = sData(rownumber - 1, lcnt)) AND...
6
by: tshad | last post by:
I have a value coming from my Object (or it could also be from a SqlDbReader) where I need to test for DBNull and 0. I tried to do it in one call: if (not (newPosition.ReportsTo is...
2
by: Brent | last post by:
We are gradually upgrading our vb6 code to .net. A lot of our shared modules in vb6 we are upgrading to .Net dlls that are shared. One problem we have is that we have VB6 modules that have optional...
1
by: darrel | last post by:
A common problem I encounter is having to enter either a date OR a null value into a date field in a DB. The problem I hace is that DBNull.value isn't a proper value for a date variable, so I...
8
by: Martin Z | last post by:
INSERT INTO dbo.Transmission (TransmissionDate, TransmissionDirection, Filename, TransmittedData) VALUES (@TransmissionDate,@TransmissionDirection,@Filename,@TransmittedData); SELECT @retVal =...
3
by: Finn Stampe Mikkelsen | last post by:
Hi I have defined a table in my database, with 2 date-fields. I have set a default value to DBNull. I have integrated a nullable datetimepicker control to my project and set the apropriate...
3
by: John | last post by:
Hi I am using a oledb reader to read from a table. The problem is that system generates an exception when MyReader.GetValue(2) returns a value of type system.dbnull. The system does not allow me...
3
by: shlabadoo | last post by:
Hello, I searched for quite a while for an answer to this, but with no joy. All the answeres seem to be how to deal with getting a DBNull value out of a database, not to put it in . Perhaps I am...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.