473,657 Members | 2,418 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Insert date 1900-01-01

Hey,
I am inserting values in the table:

Dim sqlcomm1 As SqlCommand = New SqlCommand("INS ERT INTO tblTasks
(idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
"')", conn)
sqlcomm1.Execut eNonQuery()

Query is working fine if there is value in the txtOutDate, but if user
leaves the field txtOutdate empty, system insert date 1900-01-01. I want
system to insert null.

How can I achieve that?

Regards
Arek


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #1
7 2449
in c#
txtOutdate.Text == string.empty ? null : txtOutdate.Text

i'm sorry i am not expert in visualbasic.

but i suppose you can make an if
if txtOutdate.Text == string.empty then
str = null
else
str = txtOutdate.Text

I think you should also transform your string in datetime format recognized
by sql.
"Arek" wrote:
Hey,
I am inserting values in the table:

Dim sqlcomm1 As SqlCommand = New SqlCommand("INS ERT INTO tblTasks
(idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
"')", conn)
sqlcomm1.Execut eNonQuery()

Query is working fine if there is value in the txtOutDate, but if user
leaves the field txtOutdate empty, system insert date 1900-01-01. I want
system to insert null.

How can I achieve that?

Regards
Arek


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #2
Hi Arek,

It isn't clear whether your data is supposed to be a datetime or a quoted
string. If it is a string and you want to insert a Null if the text is empty,
you can try testing with the function code below. For a datetime, you'll need
a different value. You can try hardcoding the values at first until you see
what type is acceptable.

Let us know how you make out?

Ken

<%@ Page Language="VB" %>
<script runat="server">

Sub Button1_Click(s ender As Object, e As EventArgs)
label1.text="IN SERT INTO tblTasks (idTask, outdate) VALUES ('" &
IDTask.text & "'," & CheckNull(txtOu tdate.Text) & ")"
End Sub

Function CheckNull(strIn Val as object) as string
if isNothing(strIn Val) then
return "Null"
end if

if strInval="" then
return "Null"
end if

' Everything is fine
return " '" & strInval & "' "
end function

</script>
<html>
<head>
</head>
<body>
<form runat="server">
<p>
</p>
<p>
<asp:TextBox id="IDTask" runat="server"> MyValue</asp:TextBox>
</p>
<p>
<asp:TextBox id="txtOutdate " runat="server"> The value goes
here</asp:TextBox>
</p>
<p>
<asp:Button id="Button1" onclick="Button 1_Click" runat="server"
Text="Button"></asp:Button>
</p>
<p>
<asp:Label id="Label1" runat="server"> Label</asp:Label>
</p>
<!-- Insert content here -->
</form>
</body>
</html>
"Arek" wrote:
Hey,
I am inserting values in the table:

Dim sqlcomm1 As SqlCommand = New SqlCommand("INS ERT INTO tblTasks
(idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
"')", conn)
sqlcomm1.Execut eNonQuery()

Query is working fine if there is value in the txtOutDate, but if user
leaves the field txtOutdate empty, system insert date 1900-01-01. I want
system to insert null.

How can I achieve that?

Regards
Arek


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #3
I am not a not an expert in C#, but shouldn't that be DBNull.Value?

Regardless, it is a lot cleaner using parameters...

Dim sqlcomm1 As New SqlCommand("INS ERT INTO tblTasks (idTask, outdate)
VALUES (@ID, @OutDate)", conn)

sqlcomm1.Parame ters.Add("@ID", SqlDbType.Int). Value = CInt(IDTask.tex t)

If Not txtOutdate.Text = String.Empty Then
sqlcomm1.Parame ters.Add("@OutD ate", SqlDbType.DateT ime).Value =
CDate(txtOutdat e)
Else
sqlcomm1.Parame ters.Add("@OutD ate", SqlDbType.DateT ime).Value =
DBNull.Value
End If

sqlcomm1.Execut eNonQuery()

HTH,
Greg

"Psycho" <Ps****@discuss ions.microsoft. com> wrote in message
news:BE******** *************** ***********@mic rosoft.com...
in c#
txtOutdate.Text == string.empty ? null : txtOutdate.Text

i'm sorry i am not expert in visualbasic.

but i suppose you can make an if
if txtOutdate.Text == string.empty then
str = null
else
str = txtOutdate.Text

I think you should also transform your string in datetime format
recognized
by sql.
"Arek" wrote:
Hey,
I am inserting values in the table:

Dim sqlcomm1 As SqlCommand = New SqlCommand("INS ERT INTO tblTasks
(idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
"')", conn)
sqlcomm1.Execut eNonQuery()

Query is working fine if there is value in the txtOutDate, but if user
leaves the field txtOutdate empty, system insert date 1900-01-01. I want
system to insert null.

How can I achieve that?

Regards
Arek


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 18 '05 #4
should have been...
sqlcomm1.Parame ters.Add("@OutD ate", SqlDbType.DateT ime).Value =
CDate(txtOutdat e.Text)

"Greg Burns" <greg_burns@DON T_SPAM_ME_hotma il.com> wrote in message
news:Oi******** ******@TK2MSFTN GP10.phx.gbl...I am not a not an expert in C#, but shouldn't that be DBNull.Value?

Regardless, it is a lot cleaner using parameters...

Dim sqlcomm1 As New SqlCommand("INS ERT INTO tblTasks (idTask, outdate)
VALUES (@ID, @OutDate)", conn)

sqlcomm1.Parame ters.Add("@ID", SqlDbType.Int). Value = CInt(IDTask.tex t)

If Not txtOutdate.Text = String.Empty Then
sqlcomm1.Parame ters.Add("@OutD ate", SqlDbType.DateT ime).Value =
CDate(txtOutdat e)
Else
sqlcomm1.Parame ters.Add("@OutD ate", SqlDbType.DateT ime).Value =
DBNull.Value
End If

sqlcomm1.Execut eNonQuery()

HTH,
Greg

"Psycho" <Ps****@discuss ions.microsoft. com> wrote in message
news:BE******** *************** ***********@mic rosoft.com...
in c#
txtOutdate.Text == string.empty ? null : txtOutdate.Text

i'm sorry i am not expert in visualbasic.

but i suppose you can make an if
if txtOutdate.Text == string.empty then
str = null
else
str = txtOutdate.Text

I think you should also transform your string in datetime format
recognized
by sql.
"Arek" wrote:
Hey,
I am inserting values in the table:

Dim sqlcomm1 As SqlCommand = New SqlCommand("INS ERT INTO tblTasks
(idTask, outdate) VALUES ('" & IDTask.text & "','" & txtOutdate.Text &
"')", conn)
sqlcomm1.Execut eNonQuery()

Query is working fine if there is value in the txtOutDate, but if user
leaves the field txtOutdate empty, system insert date 1900-01-01. I want
system to insert null.

How can I achieve that?

Regards
Arek


*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!


Nov 18 '05 #5
I was thinking about using parameters and converting my query to stored
procedure. The thing is that this is just part of the query and query
itself is big. So I was trying to avoid this.
Anyway, my outdate is in datetime format.
I will try to use proposed here solutions and I will post whatever
worked for me...:)

Regards
*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #6
Ok,

I finally use query with parameters and then check
If Not TxtOutDate.Text = "" Then
sqlcomm1.Parame ters.Add("@TxtO utDate",
SqlDbType.Small DateTime).Value = TxtOutDate.Text
Else
sqlcomm1.Parame ters.Add("@TxtO utDate",
SqlDbType.Small DateTime).Value = DBNull.Value
End If

This is working for me.

When I tried to use CDate or Cint, or if not txtOutdate.text =
String.Empty, system was giving me errors.

Thank you for your help
Arek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #7
Ok,

I finally use query with parameters and then check
If Not TxtOutDate.Text = "" Then
sqlcomm1.Parame ters.Add("@TxtO utDate",
SqlDbType.Small DateTime).Value = TxtOutDate.Text
Else
sqlcomm1.Parame ters.Add("@TxtO utDate",
SqlDbType.Small DateTime).Value = DBNull.Value
End If

This is working for me.

When I tried to use CDate or Cint, or if not txtOutdate.text =
String.Empty, system was giving me errors.

Thank you for your help
Arek

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 18 '05 #8

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

Similar topics

8
5180
by: Cristian Martinello | last post by:
There's a way to check if a string is a valid date ? Thanks helpers. -- Posted via Mailgate.ORG Server - http://www.Mailgate.ORG
4
2005
by: Treetop | last post by:
I have a script for my church that we use for the weekly events. I currently have it as week of Feb 1, 2003 at the top, then list Sun - Sat below the date. I have been asked to put the date next to each day of the week. I want to have the Month and Day after the day of the week. My problem is during transition weeks, from one month to the next, that I cannot figure out how to have it know to start over with day 1 on the next month.
4
20647
by: Dave | last post by:
Hi, Can anyone tell me a simple way of inserting some sort of code into a Dreamweaver template (it goes at the bottom of the page in Copyright info) that will cause the current year to be automatically inserted at spot X when the pages are viewed that were produced from the template or are linked to it? Thanks Dave
16
2093
by: KL | last post by:
I am working on a problem and desperately need help! I need to prompt a user for the numerical month of birth, day of birth and year of birth and store it in varialbes and the use the variables to build a date object. Then print the resulting date object, in it's full form. on the screen using document.write. This IS for school and I think I am starting out right, but can't quite seem to grasp what I am doing wrong, or where to go from...
8
25378
by: dlx_son | last post by:
Here is the code so far <form name="thisform"> <h3>Enter time to add to or subtract from:</h3> (If not entered, current time will be used)<br> Day: <input name="d1" alt="Day of month" size=3> Month: <input name="m1" alt="Month" size=3> Year: <input name="y1" alt="Year" size=5> (4 digits for year, e.g.
6
9337
by: Franz | last post by:
Hy all, I have a problem with a date in javascript on firefox Browser. I use this javascript method: var dataNow=new Date(); var dd=dataNow.getDate(); var mm=dataNow.getMonth()+1; var yy=dataNow.getYear();
1
6257
by: Lam | last post by:
hi Does anyone know how to insert Date to SQL server 2000? I used DataTime.Today.ToShortDateString() it shows up "1/1/1900" in the database how can I correct that? also, how can I pull out the date and compare with a new date? Thanks
4
11486
by: sam | last post by:
Possible convert VB 6 to VB.Net 1.1 for date serial function? Example, Calendar_Date = DateSerial(1900+(Julian_Date/1000), 1,Julian_Date Mod 1000) ? Calendar_Date and Julian_Date are input variable. Please advise.
3
16372
by: Bon | last post by:
Dear all How can I convert a datetime in Short Date format to General Date format and then insert into SQL database? I get a date from a field using Request("in_date"), which is in Short Date format. Afterwards, I need to convert it into General Date and then insert the date into database. But, the date is always inserted as 1/1/1900. Please give me some suggestions.
0
16489
yasirmturk
by: yasirmturk | last post by:
Standard Date and Time Functions The essential date and time functions that every SQL Server database should have to ensure that you can easily manipulate dates and times without the need for any formatting considerations at all. They are simple, easy, and brief and you should use them any time you need to incorporate any date literals or date math in your T-SQL code. create function DateOnly(@DateTime DateTime) -- Returns @DateTime...
0
8402
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, 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...
0
8734
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8508
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,...
0
7341
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, 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...
1
6172
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4164
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4323
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
1962
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1627
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.