Hi folks,
I have 2 code snippets. One works and one does not.
This first hard-coded snippet works
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = '8/16/2006'
WHERE ([rfi].[id] = @id)"
This second snippet does not work
Dim dtNow As DateTime = DateTime.Now
dRes = dtNow.ToShortDa teString
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = dRes WHERE
([rfi].[id] = @id)"
dateresolved is a Date/Time data-type. The first snippet uses single quotes
around the date but I would think the second snippet would be accepted as a
string. If I debug the value of dRes, I receive the proper format of
"8/16/2006"
Any clues you can leave me with?
Thanks,
- Glenn 3 1982
"glenn" <gl***@discussi ons.microsoft.c omwrote in message
news:69******** *************** ***********@mic rosoft.com...
Dim dtNow As DateTime = DateTime.Now
dRes = dtNow.ToShortDa teString
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = dRes WHERE
([rfi].[id] = @id)"
dateresolved is a Date/Time data-type. The first snippet uses single
quotes
around the date but I would think the second snippet would be accepted as
a
string. If I debug the value of dRes, I receive the proper format of
"8/16/2006"
Yes, but SQL Server doesn't know that. If you're building up your SQL
dynamically, then you need to format it properly...
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = '" &
dRes.ToString(" dd MMM yyyy") & "' WHERE ([rfi].[id] = @id)"
Any clues you can leave me with?
Use parameterised queries or, better still, stored procedures.
in your sql statement
UPDATE [rfi] SET [dateresolved] = dRes
WHERE ([rfi].[id] = @id)"
dRes is assumed to be a column name, as variables start with a "@". change
it to a var and pass the parameter.
-- bruce (sqlwork.com)
"glenn" <gl***@discussi ons.microsoft.c omwrote in message
news:69******** *************** ***********@mic rosoft.com...
Hi folks,
I have 2 code snippets. One works and one does not.
This first hard-coded snippet works
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = '8/16/2006'
WHERE ([rfi].[id] = @id)"
This second snippet does not work
Dim dtNow As DateTime = DateTime.Now
dRes = dtNow.ToShortDa teString
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = dRes WHERE
([rfi].[id] = @id)"
dateresolved is a Date/Time data-type. The first snippet uses single
quotes
around the date but I would think the second snippet would be accepted as
a
string. If I debug the value of dRes, I receive the proper format of
"8/16/2006"
Any clues you can leave me with?
Thanks,
- Glenn
Mark,
Thanks. It works. Hurray !!!
I'm sorry I did not think to concatenate things. Just not thinking, I guess.
- Glenn
"Mark Rae" wrote:
"glenn" <gl***@discussi ons.microsoft.c omwrote in message
news:69******** *************** ***********@mic rosoft.com...
Dim dtNow As DateTime = DateTime.Now
dRes = dtNow.ToShortDa teString
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = dRes WHERE
([rfi].[id] = @id)"
dateresolved is a Date/Time data-type. The first snippet uses single
quotes
around the date but I would think the second snippet would be accepted as
a
string. If I debug the value of dRes, I receive the proper format of
"8/16/2006"
Yes, but SQL Server doesn't know that. If you're building up your SQL
dynamically, then you need to format it properly...
Dim queryString As String = "UPDATE [rfi] SET [dateresolved] = '" &
dRes.ToString(" dd MMM yyyy") & "' WHERE ([rfi].[id] = @id)"
Any clues you can leave me with?
Use parameterised queries or, better still, stored procedures. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics |
by: rrh |
last post by:
I am trying to update a field in one table with data from another
table. The problem I'm running into is I need to base the update on a
range of data in the 2nd table.
Table 1 has:
date field
new field
table 2 has:
key field (autonumber)
|
by: BlackFireNova |
last post by:
This concerns an Access 2002 (XP) database. There are two fields,
"Notes" (Memo Field) and "Notes Update" on a form (among others)
which I am concerned with here.
Problem: I need to be able to tell when people have added notes to a
record. (this database contains 6000+ records)
I want to set it up so that "Notes Update" is updated to the current
date whenever someone actually enters data into, or modifies data in,
the "Notes"...
|
by: Rolan |
last post by:
Having tried various permutations of Before Update and well for that
matter, After Update, OnExit, OnEnter, etc. and also Locked controls,
I'm still unable to obtain the intended results. There are actually two
parts of what I'm trying to accomplish, but are interrelated. When one
part performs as it should, then upon implementation of the other,
conflicts arise and vice versa.
A form (frmEvents) is used to logged various events and one...
|
by: Maxi |
last post by:
There is a lotto system which picks 21 numbers every day out of 80
numbers.
I have a table (name:Lotto) with 22 fields (name:Date,P1,P2....P21)
Here is the structure and sample data:
"Date","P1","P2","P3","P4","P5","P6","P7","P8","P9","P10","P11","P12","P13","P14","P15","P16","P17","P18","P19","P20","P21"
1/1/2005,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21
1/2/2005,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22
|
by: Riley DeWiley |
last post by:
I have an UPDATE query that is always setting 0 records. When I cut and
paste the SQL into Access and use it, it fails in the same way unless I
coerce the date fields to be '=now()', in which case it works. I never get
errors, and if I don't try to update the date fields, I always update the
expected number of rows (1). When I do date conversion using the same
conversion function, then call CRowset::Add() to add a record to the same
table,...
| |
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: 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: 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...
|
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: 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...
|
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: 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...
| |