473,386 Members | 2,078 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,386 software developers and data experts.

Changing smalldatetime to string

I'm using these to assign a variable to a smalldatetime object in sql
server:

dim todnews = DateTime.Today.ToString ( "d" )
'connection string to server is on this line
Dim strSQL2 as string ="SELECT Arrived,Title,ID,story FROM
tblGeneral WHERE Arrived = 'todnews'"

...but I get a syntax error saying i can't change a string to
smalldatetime data type. When I try replacing DateTime.Today.ToString (
"d" ) with SmallDateTime.Today.ToString ( "d" ), the error says there
is no object named "SmallDateTime"
TIA
..netsports

Nov 20 '05 #1
2 2654
It should be
Dim strSQL2 as string ="SELECT Arrived,Title,ID,story FROM tblGeneral WHERE
Arrived = '" & todnews & "'"

Actually, it's better to use parameter like

Dim strSQL2 as string ="SELECT Arrived,Title,ID,story FROM tblGeneral WHERE
Arrived = @Arrived"
command.Parameters.Add("@Arrived", DateTime.Today)
reader = command.ExecuteReader()

HTH

Elton Wang

".Net Sports" wrote:
I'm using these to assign a variable to a smalldatetime object in sql
server:

dim todnews = DateTime.Today.ToString ( "d" )
'connection string to server is on this line
Dim strSQL2 as string ="SELECT Arrived,Title,ID,story FROM
tblGeneral WHERE Arrived = 'todnews'"

...but I get a syntax error saying i can't change a string to
smalldatetime data type. When I try replacing DateTime.Today.ToString (
"d" ) with SmallDateTime.Today.ToString ( "d" ), the error says there
is no object named "SmallDateTime"
TIA
..netsports

Nov 20 '05 #2
thanx; forgot about the concantenation operators for vb . Now that I
got the script error free, I don't see any response as far as data
returned in my script; i've tried matching the output of the
smalldatetime formatting:
dim todnews = DateTime.Today.ToString ( "yyyy/MM/dd hh:mm:ss tt" )
' the date data in the db looks like 2005/11/18 10:11:00 AM

???
..netsports

Nov 20 '05 #3

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

Similar topics

4
by: James Goodman | last post by:
I have an asp page which the user enters a time(e.g. 12:21). I need to insert this time into a SQL Server DB, which has a smalldatetime column. I have tried everything I can think of (such as...
2
by: Joey Martin | last post by:
Please help. I have a ms sql table called data. Two fields, saledate(smalldatetime),saledatetext(nvarchar) I have dates (ex. 05/04/05) in the saledatetext, but I need this converted into...
7
by: Bostonasian | last post by:
I have a table that contains transactional data. Such as site view by whom, when, which template, etc, etc... Everytime when I pulled the report, hh:mm:ss never matters. Only breakdown by dates,...
2
by: Marc Pelletier | last post by:
Hello all, I have a library of datetime routines that make things simpler for me. Before I discovered DateTime.MinValue I had a function that looked like public static DateTime DayZero { get {...
2
by: Salim Afþar | last post by:
Hi, How can I cast from datetime type to smalldatetime type. I get the records from a table which has got a datetime type column but I want to display it smalldatetime format. Thanks, Salim
3
by: Pat | last post by:
i'm passing a string as a Date as value :- for example "23/07/1988" But when trying to insert it in a column with datatype "smalldatetime" i get an error The string was not recognized as a valid...
5
by: Dimitri Furman | last post by:
This looks like a bug - hopefully somebody can explain what is actually happening. Using SQL Server 2000 SP4. Here's a repro script with comments: /* repro table */ CREATE TABLE dbo.T ( ID...
6
by: SQL Server | last post by:
I've been working this for a while. Kind of new to SQL Server functions and not seeing what I am doing wrong. I have this function CREATE FUNCTION dbo.test (@Group varchar(50)) RETURNS...
2
by: sallyme | last post by:
Hi I am passing Date value form .asp form like "3/15/2007" And i am geting error Microsoft OLE DB Provider for ODBC Drivers (0x80040E07) Syntax error converting character string to...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.