Re: Insert date into a datetime column in Visual Basic 2008
- From: Gum <gum@xxxxxxxxxxxxx>
- Date: Mon, 11 May 2009 22:50:01 -0700
I noted your canned 'wrong discussion group'. I am using ADO.net so I guess
I should go to the ADO.net discussion group although I think the issues are
more or less much the same. There were no answers to this issue there.
The cast... was my attempt to try anything after using the 'dte' directly
but nonetheless your response indicated that I needed to understand the use
of literal strings in sql commands. As an axiomatic student, I would be
grateful if you send me a link to edify. I present a more complete code to
permit a better understanding of the issue:
Dim conn As SqlConnection
Dim cmd As SqlCommand
Dim cmdString As String
Dim dte As System.DateTime
dte = DateTime.Now.ToString
cmdString = "Insert insertTB([date], [close]) Values ('dte',
'Fnumber')"
conn = New SqlConnection("Data Source=WINALL;Initial
Catalog=DataFill;Integrated Security=True")
cmd = New SqlCommand(cmdString, conn)
conn.Open()
cmd.ExecuteNonQuery()
conn.Close()
I found a 'solution' at (albeit an access database which could be easily
adjusted to SQL via the importation of the relevant library ie.
System.Data.SQLClient and changes to some of the statements eg OleDbCommand)
:
http://www.vbdotnetheaven.com/UploadFile/Ashish1/MSaccessDateInsertInVB11082005000729AM/MSaccessDateInsertInVB.aspx>
Essentially, the same issues are involved, that is how to insert a date into
a datetime db. However, I was not successful in copying the example, possibly
due to the terse explanations given.
"Bob Barrows" wrote:
Gum wrote:.
I need to insert a date (i.e., "2009/05/12 02:46" or
system.datetime.tostring) into a datetime column using ADO. I got an
error saying that there is a problem converting the string into
datetime.
I am using a SQL string "INSERT insertTB([date],[close])
values('cast(dte as datetime)', 'Fnumber')"
How can I do this insert using the most efficient method?
Why would you think the string 'cast(dte as datetime)' could be inserted
into a datetime column? You do realize that's a literal string, don't you? I
think more of your code is necessary to enable someone to solve your
problem.
Are you using ADO or ADO.Net? If the latter:
***canned wrong-newsgroup reply************************
There was no way for you to know it (except maybe by browsing through some
of the previous questions in this newsgroup before posting yours - always a
recommended practice) , but this is a classic (COM-based) ADO newsgroup.
ADO.Net bears very little resemblance to classic ADO so, while you may be
lucky enough to find a dotnet-knowledgeable person here who can answer your
question, you can eliminate the luck factor by posting your question to a
group where those dotnet-knowledgeable people hang out. I suggest
microsoft.public.dotnet.framework.adonet.
..******************************************************************
--
Microsoft MVP - ASP/ASP.NET - 2004-2007
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
- Follow-Ups:
- Re: Insert date into a datetime column in Visual Basic 2008
- From: Daniel Crichton
- Re: Insert date into a datetime column in Visual Basic 2008
- References:
- Insert date into a datetime column in Visual Basic 2008
- From: Gum
- Re: Insert date into a datetime column in Visual Basic 2008
- From: Bob Barrows
- Insert date into a datetime column in Visual Basic 2008
- Prev by Date: Re: Insert date into a datetime column in Visual Basic 2008
- Next by Date: Re: Insert date into a datetime column in Visual Basic 2008
- Previous by thread: Re: Insert date into a datetime column in Visual Basic 2008
- Next by thread: Re: Insert date into a datetime column in Visual Basic 2008
- Index(es):
Relevant Pages
|