Hi folks,
I guess this question has to do with formatting dates. Seems like it should
be a no brainer but have spent too much time hunting so I am posting the
forum.
I have a function that needs to pass a Date data-type that is empty much
like a string would be empty if we were to place double quotes as in "".
The reason it needs to be empty is because I am passing parameters to a
database with an INSERT statement and if I pass a Null value, I get errors in
other parts of my web application.
Thanks for any insight on this.
glenn 2 1947
Pass a NULL, and in your stored procedure, handle the NULL appropriately.
You are using sprocs for everything, right?
Jeff
"glenn" <gl***@discussi ons.microsoft.c om> wrote in message
news:03******** *************** ***********@mic rosoft.com... Hi folks,
I guess this question has to do with formatting dates. Seems like it should be a no brainer but have spent too much time hunting so I am posting the forum.
I have a function that needs to pass a Date data-type that is empty much like a string would be empty if we were to place double quotes as in "".
The reason it needs to be empty is because I am passing parameters to a database with an INSERT statement and if I pass a Null value, I get errors in other parts of my web application.
Thanks for any insight on this. glenn
Glenn,
As you may already know the DateTime type can't be null. When declare:
DateTime dayToPass;
It's essentially the same as:
DateTime dayToPass = new DateTime();
Which has a value of "1/1/0001 12:00:00 AM" for both declarations.
So when you want to see if a DateTime variable was set or "null" you
can just do something like this:
private bool isValidDate(Dat eTime param)
{
DateTime nullDate = new DateTime();
return (param != nullDate);
}
That should do the validation for you.
Now when you are trying to setup the parameters for a datetime data
type in the stored procedure command, you can do this to pass in a
valid date time or a null if it's not valid. Here is an example of how
you could set up the function that would update a record with a valid
date or null value:
private void UpdateShippemen t(int deliveryId, string address, DateTime
shippedOn, int status)
{
SqlConnection setupconnection ;
SqlCommand command = new SqlCommand();
command.Connect ion = setupconnection ;
command.Command Type = System.Data.Com mandType.Stored Procedure;
command.Command Text = "dbo.StoredProc ToUse";
SqlParameter pDeliveryID = new SqlParameter("@ DeliveryID",
SqlDbType.Int);
SqlParameter pAddress = new SqlParameter("@ Address",
SqlDbType.VarCh ar, 50);
SqlParameter pShippedOn = new SqlParameter("@ ShippedOn",
SqlDbType.DateT ime);
pDeliveryID.Val ue = deliveryId;
pAddress.Value = address;
if (isValidDate(sh ippedOn))
{
pShippedOn.Valu e = shippedOn;
}
else
{
pShippedOn.Valu e = DBNull.Value;
}
int returnValue = command.Execute NonQuery();
}
I hope that helped, or atleast helped you think in the right
direction.... Have a good one.
Jose This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: Jill |
last post by:
I am trying to store the current date to an ms access database on my server.
I set it up with a dsnless connection.
Here is the statement:
Insert Into employees(timestamp) Values ('" & date() & "')"
the timestamp field is of type date/time in the ms access database.
I get an error saying the insert statement is invalid. Cannot get you the
exact error, my server is down.
But it seems that the syntax is correct.
|
by: Bill |
last post by:
Hello out there;
This may be a challenge but I'm certain it's possible but I can't seem
to figure out how.
I have a table that has several date fields, e.g., Date1, Date2,
Date3, Date4 ... etc. I wish to find out either of two things for
each row.
1) What is the maximun date in any of the date fields in the row.
|
by: Fresh Air Rider |
last post by:
Hello
Could anyone please explain how I can pass more than one
arguement/parameter value to a function using <asp:linkbutton> or is
this a major shortfall of the language ?
Consider the following code fragments in which I want to list through
all files on a directory with a link to download each file by passing
a filename and whether or not to force the download dialog box to
appear.
|
by: Chris |
last post by:
Hi,
I am storing dates in sql server in this format
2005-04-13 22:22:16.353
My asp.net app is passing the date as string like this 4/13/2005
to the foll sp
|
by: Oenone |
last post by:
In our applications, we use the special value of DateTime.MinValue to
represent "null dates" throughout all our code. We recently ran into an
issue where we wanted an optional date parameter for a procedure. We weren't
able to declare it with DateTime.MinValue as its default value, as MinValue
is a read-only property rather than a constant. To work around, we had to
use a "magic date" that we checked for later on. I was never very happy...
| |
by: Bill |
last post by:
I have a 200 record database that includes a date/time field,
AnnivDate, for a wedding anniversary. AnnivDate has nulls and some
incorrect year data. I have been creating the Access database using
data imported from an Excel file and the person entering into Excel
only cared about the month and day portion and Excel added the current
year to the field value. I want to produce a report that shows
upcoming anniversaries using a parameter...
|
by: vijaykumardahiya |
last post by:
Hello Sir,
I have a simple Issue but It is not resolve by me i.e input parameter
are not store in Ms-Access.
I store the input parameter through Standard Action <jsp:useBean>.
jsp:useBean call a property IssueData. this property exist in
SimpleBean which create a connection from DB and insert the data.
At run time servlet and server also show that loggging are saved in DB.
But when I open the table in Access. Its empty.
Ms-Access have...
|
by: Dormilich |
last post by:
Hi,
I'm testing my classes for a web page and I stumble upon an error I don't have a clue what it means:
Error:
Fatal error: Can't use method return value in write context in "output.php" on line 142 (line 12 in snippet)
the error is caused by this call:
empty($inSeite_inp->getValue('PAR_NAME'))
method definition see second snippet, lines 142 to 166
|
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look !
Part I. Meaning of...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed.
This is as boiled down as I can make it.
Here is my compilation command:
g++-12 -std=c++20 -Wnarrowing bit_field.cpp
Here is the code in...
| |
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
|
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one.
At the time of converting from word file to html my equations which are in the word document file was convert into image.
Globals.ThisAddIn.Application.ActiveDocument.Select();...
|
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |