Basic Date Picker Forums

Welcome to Basic Date Picker Forums Sign in | Join | Help
in Search

Problems getting date to post after editing existing record.

Last post 05-17-2006, 4:26 PM by geoffrey.mcgill. 1 replies.
Sort Posts: Previous Next
  •  05-17-2006, 4:12 PM 517

    Problems getting date to post after editing existing record.

    We were able to implement the BDPlite version with no troubles until we tried to edit an existing record in our database.  I can create new records all day long, but when you go to edit an existing records date ,the date picker works, but when you save, the following error is thrown.

    _____________________________________________________________________

    Server Error in '/indytest' Application.

    Cast from string "" to type 'Date' is not valid.

    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.InvalidCastException: Cast from string "" to type 'Date' is not valid.

    Source Error:

    Line 201:        cD.FullName = Request.Form("ddlContactPeople")
    Line 202:        cD.ContactDate = bdplite.SelectedDate
    Line 203:        cD.ContactDate = Request.Form("bdplite")
    Line 204:        cD.ActivityCode = Request.Form("ddlActivityCode")
    Line 205:        cD.BarrierType = Request.Form("ddlBarrierType")


    Source File: C:\Inetpub\wwwroot\indytest\editContact.aspx.vb    Line: 203

    Stack Trace:

    [InvalidCastException: Cast from string "" to type 'Date' is not valid.]
       Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value, CultureInfo culture)
       Microsoft.VisualBasic.CompilerServices.DateType.FromString(String Value)
       CimroIndyApps.editContact.btnSaveContact_Click(Object sender, EventArgs e) in C:\Inetpub\wwwroot\indytest\editContact.aspx.vb:203
       System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       System.Web.UI.Page.ProcessRequestMain()
    

    _________________________________________________________________

    Here is the code.

    Imports

    System.Data

    Imports

    System.Data.SqlClient

    Public

    Class editContact

    Inherits System.Web.UI.Page

    #

    Region " Web Form Designer Generated Code "

    'This call is required by the Web Form Designer.

    <System.Diagnostics.DebuggerStepThrough()>

    Private Sub InitializeComponent()

    End Sub

    Protected WithEvents Label2 As System.Web.UI.WebControls.Label

    Protected WithEvents Label1 As System.Web.UI.WebControls.Label

    Protected WithEvents lblOrgID As System.Web.UI.WebControls.Label

    Protected WithEvents lblOrgName As System.Web.UI.WebControls.Label

    Protected WithEvents lblOrgType As System.Web.UI.WebControls.Label

    Protected WithEvents lblAddr As System.Web.UI.WebControls.Label

    Protected WithEvents lblCity As System.Web.UI.WebControls.Label

    Protected WithEvents lblState As System.Web.UI.WebControls.Label

    Protected WithEvents tbOrgID As System.Web.UI.WebControls.TextBox

    Protected WithEvents ddlContactTypes As System.Web.UI.WebControls.DropDownList

    Protected WithEvents tbCreatedBy As System.Web.UI.WebControls.TextBox

    Protected WithEvents tbCreateDate As System.Web.UI.WebControls.TextBox

    Protected WithEvents tbUpdatedBy As System.Web.UI.WebControls.TextBox

    Protected WithEvents tbUpdateDate As System.Web.UI.WebControls.TextBox

    Protected WithEvents btnDelete As System.Web.UI.WebControls.Button

    Protected WithEvents ddlContactPeople As System.Web.UI.WebControls.DropDownList

    Protected WithEvents tbNotes As System.Web.UI.WebControls.TextBox

    Protected WithEvents ddlCommType As System.Web.UI.WebControls.DropDownList

    Protected WithEvents btnSaveContact As System.Web.UI.WebControls.Button

    Protected WithEvents ddlActivityCode As System.Web.UI.WebControls.DropDownList

    Protected WithEvents lblActivityCode As System.Web.UI.WebControls.Label

    Protected WithEvents ddlBarrierType As System.Web.UI.WebControls.DropDownList

    Protected WithEvents lblBarrierType As System.Web.UI.WebControls.Label

    Protected WithEvents CompareValidator2 As System.Web.UI.WebControls.CompareValidator

    Protected WithEvents RequiredFieldValidator1 As System.Web.UI.WebControls.RequiredFieldValidator

    Protected WithEvents bdplite As BasicFrame.WebControls.BDPLite

    'NOTE: The following placeholder declaration is required by the Web Form Designer.

    'Do not delete or move it.

    Private designerPlaceholderDeclaration As System.Object

    Private Sub Page_Init(ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles MyBase.Init

    'CODEGEN: This method call is required by the Web Form Designer

    'Do not modify it using the code editor.

    InitializeComponent()

    End Sub

    #

    End Region

    Public currCId As String

    Public currOrgId As String

    Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles MyBase.Load

    'Put user code to initialize the page here

    Label1.Text = "You are logged in as " + User.Identity.Name

    currCId = Request.QueryString("cID")

    currOrgId = Request.QueryString("oID")

    Dim org As New Org

    Dim orgD As Org.OrgDetails = New Org.OrgDetails

    If Not (currOrgId.Equals("0")) Then

    'Get the organization based on org id passed in

    orgD = org.GetOrgDetails(currOrgId)

    lblOrgID.Text = orgD.OrgID

    lblOrgName.Text = orgD.Name

    lblOrgType.Text = orgD.OrgType

    lblAddr.Text = orgD.AddrLine1

    lblCity.Text = orgD.City

    lblState.Text = orgD.State

    End If

    'check to see if a new contact

    If Not (currCId.Equals("0")) Then

    'Get the person based on people id passed in

    Dim contact As New Contact

    Dim cD As Contact.ContactDetails = New Contact.ContactDetails

    cD = contact.GetContactDetails(currCId)

    PopulateContactPeople(cD.FullName)

    tbOrgID.Text = currOrgId

    ' changed for BasicDatePicker

    bdplite.SelectedDate = cD.ContactDate

    PopulateActivityCode(cD.ActivityCode, orgD.OrgType)

    PopulateBarrierType(cD.BarrierType, orgD.OrgType)

    PopulateCommTypeList(cD.CommType)

    tbNotes.Text = cD.Notes

    tbCreatedBy.Text = cD.CreatedBy

    tbCreateDate.Text = cD.CreateDate

    tbUpdatedBy.Text = User.Identity.Name

    tbUpdateDate.Text =

    Date.UtcNow.ToLocalTime.ToString("MM/dd/yyyy")

     

    Else

    'A new contact

    ' below not needed with Basic Date Picker, it has own default

    'tbContactDate = Date.UtcNow.ToLocalTime.ToString("MM/dd/yyyy")

    tbOrgID.Text = currOrgId

    tbCreatedBy.Text = User.Identity.Name

    tbCreateDate.Text =

    Date.UtcNow.ToLocalTime.ToString("MM/dd/yyyy")

    tbUpdatedBy.Text = User.Identity.Name

    tbUpdateDate.Text =

    Date.UtcNow.ToLocalTime.ToString("MM/dd/yyyy")

    PopulateContactPeople("none")

    'pass in the orgtype as well to filter

    'orgD.OrgType

    PopulateActivityCode("none", orgD.OrgType)

    PopulateBarrierType("none", orgD.OrgType)

    PopulateCommTypeList("none")

    End If

     

    End Sub

    Private Sub PopulateCommTypeList(ByVal commType As String)

    Dim contact As Contact = New Contact

    Dim reader As SqlDataReader = contact.GetCommTypeList()

    ddlCommType.DataSource = reader

    ddlCommType.DataBind()

    If Not (commType.Equals("none")) Then

    ddlCommType.SelectedValue = commType

    Else

    ddlCommType.SelectedIndex = 0

    End If

    reader.Close()

    End Sub

    Private Sub PopulateContactPeople(ByVal fName As String)

    Dim contact As Contact = New Contact

    Dim reader As SqlDataReader = contact.GetContactPeopleList(currOrgId)

    ddlContactPeople.DataSource = reader

    ddlContactPeople.DataBind()

    If (fName <> "none") Then

    ddlContactPeople.SelectedValue = fName

    Else

    ddlContactPeople.SelectedIndex = 0

    End If

    reader.Close()

    End Sub

    Private Sub PopulateActivityCode(ByVal aT As String, ByVal oType As String)

    Dim contact As Contact = New Contact

    Dim reader As SqlDataReader = contact.GetActivityCodeByOrgType(oType)

    ddlActivityCode.DataSource = reader

    ddlActivityCode.DataBind()

    If (ddlActivityCode.Items.Count > 0) Then

    If (aT <> "none") Then

    ddlActivityCode.SelectedValue = aT

    Else

    ddlActivityCode.SelectedIndex = 0

    End If

    Else

    ddlActivityCode.Visible =

    False

    lblActivityCode.Visible =

    True

    End If

    reader.Close()

    End Sub

    Private Sub PopulateBarrierType(ByVal bT As String, ByVal oType As String)

    Dim contact As Contact = New Contact

    Dim reader As SqlDataReader = contact.GetBarrierTypeByOrgType(oType)

    ddlBarrierType.DataSource = reader

    ddlBarrierType.DataBind()

    If (ddlBarrierType.Items.Count > 0) Then

    If (bT <> "none") Then

    ddlBarrierType.SelectedValue = bT

    Else

    ddlBarrierType.SelectedIndex = 0

    End If

    Else

    ddlBarrierType.Visible =

    False

    lblBarrierType.Visible =

    True

    End If

    reader.Close()

    End Sub

    Private Sub btnSaveContact_Click(ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles btnSaveContact.Click

    Dim cID As Int32

    Dim contact As New Contact

    Dim cD As Contact.ContactDetails = New Contact.ContactDetails

    cD.OrgID = currOrgId

    cD.FullName = Request.Form("ddlContactPeople")

    cD.ContactDate = bdplite.SelectedDate

    cD.ContactDate = Request.Form("bdplite")

    cD.ActivityCode = Request.Form("ddlActivityCode")

    cD.BarrierType = Request.Form("ddlBarrierType")

    cD.CommType = Request.Form("ddlCommType")

    cD.Notes = Request.Form("tbNotes")

    cD.CreatedBy = Request.Form("tbCreatedBy")

    cD.CreateDate = Request.Form("tbCreateDate")

    cD.UpdatedBy = Request.Form("tbUpdatedBy")

    cD.UpdateDate = Request.Form("tbUpdateDate")

    cID = contact.UpdateContact(currCId, currOrgId, cD)

    Response.Redirect("people_contacts.aspx?oID=" + currOrgId)

    End Sub

    Private Sub btnDelete_Click(ByVal sender As System.Object, ByVal e As System.EventArgs ) Handles btnDelete.Click

    Dim contact As New Contact

    contact.DeleteContact(currCId)

    Response.Redirect("people_contacts.aspx?oID=" + currOrgId)

    End Sub

    Private Sub btnClearDate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs )

    'tbContactDate.Text = ""

    End Sub

    End

    Class

     

  •  05-17-2006, 4:26 PM 518 in reply to 517

    Re: Problems getting date to post after editing existing record.

    Hi frinksterj,

    At firt glance it looks like your "ContactDate" property is of type String and the date picker returns a DateTime object when you get SelectedDate. Setting a string property with a DateTime object will cause an Exception.

    Confirm that when you set/get "ContactDate" that you are dealing with DateTime objects. The same Exception would occur if you were using the standard Microsoft Calendar control.

    I will have another quick look through your sample to see if I can spot anything else.

    The following Sample may also help with some code to check if a valid date exists, both coming and going from the database. See http://basicdatepicker.com/samples/item3.aspx.

    Hope this helps.
    Thanks,
    Geoffrey McGill
    ----------------------------------------
    Coolite Inc.
    Email: support [at] coolite [dot] com
    Phone: +1(888)775-5888
View as RSS news feed in XML
 
Powered by Community Server, by Telligent Systems