Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
What should I do for NULLs?
Message
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
OS:
Windows XP
Network:
Windows 2003 Server
Database:
MS SQL Server
Miscellaneous
Thread ID:
01331280
Message ID:
01331320
Views:
7
If NULLS are the problem, you could replace null values in your select statement by using the ISNULL clause for the columns that could have a NULL value and replace with a space as follows:

select isnull(columnName, ' ') as columnName

>Hi everybody,
>
>I've added new conditional tab to my FormView. I'm getting System.InvalidCastException was unhandled by user code
> Message="Specified cast is not valid."
>
> at System.Web.UI.Control.OnDataBinding(EventArgs e)
> at System.Web.UI.Control.DataBind(Boolean raiseOnDataBinding)
> at System.Web.UI.Control.DataBind()
> at System.Web.UI.Control.DataBindChildren()
> InnerException:
>
>I retrieve the data using LEFT JOIN, so my fields are NULL. Here is what I put on the ASPX
>
>  <!-- 6th -->
>                                <div id="info6" class="cl dn">
>                                    <MembInfo:MembershipInfo ID="MembershipInfoRegular" runat="server"
>                                    BillQuaterly ='< %# Bind("BillQuaterly") % >' IsMember ='< %# Bind("IsMember") % >'
>                                    PaymentMethod='< %# Bind("PaymentMethod") % >' StartDate ='< %# Bind("StartDate") % >' />
>                                </div>
>                                <!-- /6th -->
>
>and this is my UserControl:
>
>
>using System;
>using System.Collections;
>using System.Collections.Generic;
>using System.Configuration;
>using System.Data;
>using System.Web;
>using System.Web.Security;
>using System.Web.UI;
>using System.Web.UI.HtmlControls;
>using System.Web.UI.WebControls;
>using System.ComponentModel;
>
>public partial class Coordinator_UCD_MembershipInfo : System.Web.UI.UserControl
>{
>    #region Custom Properties
>    ///
>    /// <summary>The EditMode property is responsible for the Enabled style of the controls</summary>
>    ///
>    private bool editMode ;
>    [Description("The EditMode property is responsible for the Enabled style of the controls"), DefaultValue(true),Category("User-Defined")]
>    public bool EditMode
>    {
>        get { return editMode ; }
>        set {
>            editMode = value;
>            clseditmode.SetEnabled(this.Controls, value);
>        }
>    }
>
>    [Bindable(true, BindingDirection.TwoWay), Category("User-Defined"),DefaultValue(false),Description("Is User a Member?")  ]
>    public bool? IsMember
>    {
>        get
>        {
>            return this.chkIsMember.Checked;
>        }
>        set
>        {
>            this.chkIsMember.Checked = Convert.ToBoolean(value);
>        }
>    }
>    [Bindable(true, BindingDirection.TwoWay), Category("User-Defined"), DefaultValue(false), Description("Bill Quaterly?")  ]
>    public bool? BillQuaterly
>    {
>        get
>        {
>            return this.chkBillQuaterly.Checked;
>        }
>        set
>        {
>            this.chkBillQuaterly.Checked = Convert.ToBoolean(value);
>        }
>    }
>
>    [Bindable(true, BindingDirection.TwoWay), Category("User-Defined"), DefaultValue(""), Description("Payment Method") ]
>    public string PaymentMethod
>    {
>        get
>        {
>            return this.ddlPaymentMethod.SelectedValue;
>        }
>        set
>        {
>            this.ddlPaymentMethod.SelectedValue = value;
>        }
>    }
>    [Bindable(true, BindingDirection.TwoWay), Category("User-Defined"), Description("Membership Begin Date") ]
>    public DateTime? StartDate
>    {
>        get
>        {
>            return Convert.ToDateTime(this.txtMembershipStartDate.Text) ;
>        }
>        set
>        {
>            this.txtMembershipStartDate.Text = (Convert.ToDateTime(value)).ToShortDateString() ;
>        }
>    }
>   #endregion
>    protected void Page_Load(object sender, EventArgs e)
>    {
>
>    }
>}
>
>
>I'm not sure what should I do to make it work correctly with NULLs. I tried to change data types to be nullable, but this didn't help.
>
>Thanks a lot in advance.
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform