Changing smalldatetime to string

N

.Net Sports

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
 
G

Guest

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
 
N

.Net Sports

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top