VB.NET

Moderators: seancampbell
Number of threads: 4022
Number of posts: 10035

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
Updating date Posted by thushara on 7 Apr 2010 at 1:43 AM
cmd = New SqlCommand("update tb_projectpara set customer='" & cmbCustomer.Text & "', date = '" & dtpEndDate.Value.Date & "' where projectno='" & txtProjectNo.Text & "' and date='" & dat2 & "' and customer='" & cmbCustomer.Text & "'", con)
cmd.ExecuteNonQuery()
''
Everything works fine except date,its not updating in the database.
it is datepicker component.



plz chk it out



Report
Re: Updating date Posted by seancampbell on 7 Apr 2010 at 5:58 AM
There are two things I see that could be causing this not to update.

The first one is ProjectNo = 'value'. If projectNo is a number field (int, float, etc) then sending it something in single quotes will cause it to fail. I don't know what you have this feild configured as, so it's something to look into...

The second one is "where date='" & dat2 & "'". If you're using SQL Server, datetime values store exact times and dates. If you want to update a record, based on the date, you have to do something like this:
        Dim BegDate As Date = CDate(Format(Now, "MM/dd/yyyy") & " 12:00:00AM")
        Dim EndDate As Date = CDate(Format(Now, "MM/dd/yyyy") & " 11:59:59PM")
        cmd = New SqlCommand("UPDATE tb_projectpara SET customer = '" & cmbCustomer.Text & "', date = '" & dtpEndDate.Value.Date & "' WHERE projectno = '" & txtProjectNo.Text & "' AND (date >= '" & BegDate.ToString & "' AND date <= '" & EndDate.ToString & "') AND customer = '" & cmbCustomer.Text & "'", con)
        cmd.ExecuteNonQuery()


I think that is your problem. If that doesn't work. I suggest trying to get your SQL Statement working in SQL Management Studio, or with Visual Studio's built in Server Explorer and SQL Query Writer to figure out what may be wrong with your SQL Syntax.

Happy coding,
FireSickle.com
Report
Re: Updating date Posted by thushara on 7 Apr 2010 at 10:54 PM
The datatype i am using is datetime.I tried the code that you have given to me.but its not updating
Report
Re: Updating date Posted by thushara on 19 Apr 2010 at 1:34 AM
Thanku ,yes i got
Report
Re: Updating date Posted by bocaccio on 6 May 2010 at 6:45 PM
Is this for a movie rental project? If so I may need some clarification/help. I'll be online racking my brain with this on Saturday and one that is due on Sunday too. I am not doing too well in this class.
Report
Re: Updating date Posted by bocaccio on 6 May 2010 at 6:47 PM
Sorry for double posting. I thought it didn't go through and ended up going through 2*. I am not sure how to or if i can delete.



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.