.NET Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
 
User Name:
Password:
Remember me
Go Back   ASP Free ForumsProgramming.NET Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread ASP Free Forums Sponsor:
  #1  
Old February 20th, 2003, 08:09 PM
joephoenix joephoenix is offline
Registered User
ASP Free Newbie (0 - 499 posts)
 
Join Date: Jan 2003
Posts: 26 joephoenix User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 0
Inserting date values into SQL

If this isn't in the right subject forum, feel free to move it to a more appropriate one. This involves ASP and VB issues as well as SQL.<br><br>I'm trying to insert values from dropdown lists into a SQL Field who's data type is 'datetime'. Since the values from the lists are string, I've tried using Cdate to convert the data but I get an error when I do that:<br><br>System.InvalidCastException: Cast from string "" to type 'Date' is not valid.<br><br>Here's what I have in the code, server-side:<br><div class="msgQuoteWrap"><div class="msgCode"><br>Public Sub btnSave_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnSave.Click<br> Dim dateInfo As New System.Globalization.DateTimeFormatInfo()<br> Dim MyMonth, MyMonth2, MyDay, MyDay2, MyYear, MyYear2 As Date<br> MyMonth = CDate(ddlMonth.SelectedItem.Value)<br> MyDay = CDate(ddlDay.SelectedItem.Value)<br> MyYear = CDate(ddlYear.SelectedItem.Value)<br> MyMonth2 = CDate(ddlMonth2.SelectedItem.Value)<br> MyDay2 = CDate(ddlDay2.SelectedItem.Value)<br> MyYear2 = CDate(ddlYear2.SelectedItem.Value)<br> If txtWhatObjectGetsFocus.Text = "lnkAdd" Then<br> 'adding record to umv_messages SQL table<br> Dim objSQLMsgInfo As New SQLComponent()<br> objSQLMsgInfo.strConnection = objConstants.DBConnectionString_Umove<br> objSQLMsgInfo.strSQL = "INSERT INTO umv_memoManagement (mgt_memoURL, mgt_memoDescription, mgt_forWhatGroup, mgt_forWhatMemberInGroup, mgt_effectiveStartDate, mgt_effectiveEndDate) _<br> VALUES ('" & lstMemos.SelectedItem.Text & "' , '" & txtDescrip.Text & "' , '" & ddlGroup.SelectedItem.Value & "' , '" & ddlMember.SelectedItem.Value & "' , '" & _<br> Trim(MyMonth) & "/" & Trim(MyDay) & "/" & Trim(MyYear) & "' , '" & Trim(MyMonth2) & "/" & Trim(MyDay2) & "/" & Trim(MyYear2) & "')"<br> objSQLMsgInfo.ExecuteSqlStatement()<br> 'indicating message was added<br> lblMessage.Text = "MESSAGE ADDED!"<br> Else<br> 'update the umv_message table indicating message has been read<br> Dim objSqlMessageUpdate As New SQLComponent()<br> objSqlMessageUpdate.strConnection = objConstants.DBConnectionString_Umove<br> objSqlMessageUpdate.strSQL = "UPDATE umv_memoManagement SET mgt_memoDescription = " & txtDescrip.Text & ", mgt_forWhatGroup = " & ddlGroup.SelectedItem.Value & ", mgt_forWhatMemberInGroup = " & ddlMember.SelectedItem.Value & _<br> ", mgt_effectiveStartDate = " & Trim(MyMonth) & "/" & Trim(MyDay) & "/" & Trim(MyYear) & ", mgt_effectiveEndDate = " & Trim(MyMonth2) & "/" & Trim(MyDay2) & "/" & Trim(MyYear2) & " WHERE mgt_memoURL = " & Trim(lstMemos.SelectedItem.Text)<br> objSqlMessageUpdate.ExecuteSqlStatement()<br> 'indicating message was updated<br> lblMessage.Text = "MESSAGE UPDATED!"<br> End If<br>End Sub</div></div><br><br>On the client-side for the Dropdown control "ddlMonth", I've given the alpha months numeric values. I had hoped this would ease the date-conversion process; apparently it hasn't worked.<br><br>Can anyone help? <img src="/forum/emoticons/confused.gif" alt="confused">

Reply With Quote
Reply

Viewing: ASP Free ForumsProgramming.NET Development > Inserting date values into SQL


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 5 hosted by Hostway
Stay green...Green IT