Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / .NET Framework / New Users / August 2005

Tip: Looking for answers? Try searching our database.

Updateing Datetime field

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
TnCoder - 23 Aug 2005 19:38 GMT
Hi;
   I have a pocket pc app that allows users to select a date. The selection
is in a string format; example: 08/21/2005. When I try to update the
database, the date is put in as 01/01/1900 00:00:00. My SQL code snippet is:
Admit_Date = convert(datetime," & tempdate & ",120)
Where Admit_Date is the database field name, Tempdate is the user entered
variable as string.

Thanks in advance for all the help

Dale
rico - 24 Aug 2005 01:25 GMT
Instead of sending the data directly to the database, first convert it to a
string and view the string value in the debug window, you may not be getting
what you think you are getting to begin with. In short make sure your
convertion is working.

> Hi;
>     I have a pocket pc app that allows users to select a date. The selection
[quoted text clipped - 7 lines]
>
> Dale
TnCoder - 24 Aug 2005 13:25 GMT
Dear Rico;

Thank you for the repy. Yes, I have tried viewing the result in the debug
window and it is what I expected. Any other suggestions? I will try anything
at this point.

Thanks a bunch

Dale

> Instead of sending the data directly to the database, first convert it to a
> string and view the string value in the debug window, you may not be getting
[quoted text clipped - 12 lines]
> >
> > Dale
rico - 24 Aug 2005 14:30 GMT
Ok, try doing this entirely in VB instead of your SQL. Try this instead,
Admit_Date = system.convert.todatetime(dateTimeString). It may well be that
the SQL function you are calling in your VB code is not getting 'fired' in
SQL.  Alternately, set a stored proc in the database and pass your date
string in as a parameter. One of these approaches should work. Of note, date
time is always a bear with proceedural languages to and DBMS. Never seems to
want to go smoothly <wink>.

Shout back the result.

> Dear Rico;
>
[quoted text clipped - 22 lines]
> > >
> > > Dale
TnCoder - 25 Aug 2005 19:29 GMT
Thanks for the reply Rico! My thoughts exactly were to do the same, go
through VB. But now I have another problem. First here is my code:

       Dim ds As DataSet = Nothing
       Dim dtachg As System.Data.SqlServerCe.SqlCeDataAdapter = Nothing
       Dim cn As System.Data.SqlServerCe.SqlCeConnection = Nothing
       cn = CMClientGlobals.CM_Database.EstablishConnection()
       If cn.State = ConnectionState.Closed Then
           cn.Open()
       End If
       dtachg = New System.Data.SqlServerCe.SqlCeDataAdapter
       dtachg.SelectCommand = New SqlCeCommand
       dtachg.SelectCommand.Connection = cn
       dtachg.SelectCommand.CommandText = "Select * from Charges where
TRANSID = " & ENC_NUM
       ds = New DataSet
       dtachg.FillSchema(ds, SchemaType.Source, "Charges")
       dtachg.Fill(ds, "Charges")
       Dim dt As DataTable = ds.Tables(0)
       If dt.Rows.Count = 1 Then
           Dim dr As DataRow
           dr = dt.Rows(0)
           dr.BeginEdit()
           dr("provider") = Provider
           dr("Facility_Code") = Facility_Code
           dr("dx1") = Dx1
           dr("dx2") = Dx2
           dr("dx3") = Dx3
           dr("dx4") = Dx4
           dr("dos") = Admit_Date
           dr("chargecode") = ChargeCode
           dr.EndEdit()
           Dim objCommandBuilder As New SqlCeCommandBuilder(dtachg)
           dtachg.UpdateCommand = objCommandBuilder.GetUpdateCommand
           dtachg.Update(ds, "charges")
       end if

now I am getting the error:

An unhandled exception of type 'System.InvalidOperationException' occurred
in System.Data.SqlServerCe.dll

Additional information: Dynamic SQL generation for the UpdateCommand is not
supported against a SelectCommand that does not return any key column
information.

I have tried setting the primarykey with dt.primarykey = "TRANSID", but I
continue to get the same error.

Any thoughts

> Ok, try doing this entirely in VB instead of your SQL. Try this instead,
> Admit_Date = system.convert.todatetime(dateTimeString). It may well be that
[quoted text clipped - 32 lines]
> > > >
> > > > Dale
TnCoder - 25 Aug 2005 19:44 GMT
I forgot to mention that the "TRANSID" was set in an array when I tried to
make it the primary key

> Thanks for the reply Rico! My thoughts exactly were to do the same, go
> through VB. But now I have another problem. First here is my code:
[quoted text clipped - 83 lines]
> > > > >
> > > > > Dale

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.