You must Sign In to post a response.
  • Category: ASP.NET

    Problem in datatype of boolean

    getting this error " String was not recognized as a valid Boolean."
    we are using 3-tier architecture
    1.stored procedure is
    create procedure editstatus @tstatusname varchar(20),@tstatus bit
    as
    begin
    update status set status=@tstatus where statusname=@tstatusname
    end


    2.in business access layer.the code is

    public string _statusname;
    public Boolean m_status;
    public string statusname
    {
    get
    {
    return _statusname;
    }
    set
    {
    _statusname = value;
    }
    }

    public Boolean status1
    {
    get
    {
    return m_status;
    }
    set
    {
    m_status = value;
    }
    }

    public int editstatus()
    {
    SqlParameter[] p = new SqlParameter[2];
    p[0] = new SqlParameter("@tstatusname", statusname);
    p[1] = new SqlParameter("@tstatus", status1);


    int res = dal.ExecuteNonquery(dal.connection, CommandType.StoredProcedure, "editstatus", p);
    return res;
    }

    3. in codebehind window code is
    status obj = new status();

    protected void Button1_Click(object sender, EventArgs e)
    {

    obj._statusname = TextBox2.Text.ToString();
    obj.m_status = Convert.ToBoolean(RadioButtonList1.SelectedValue);
    int result = obj.editstatus();
    }
  • #687782
    hi,

    are you getting error here?
    obj.m_status = Convert.ToBoolean(RadioButtonList1.SelectedValue);

    but i checked it is working fine.
    check by using try catch blocks in each and every function. so you can trace it easily where it is happening.

    Rayala HariKishore

    try..try..try...you achieved it.
    http://rayalaharikishore.wordpress.com/

  • #687783
    Try this code in BL

    private string _statusname= string.Empty;
    private bool? m_status= null;
    public bool? status1
    {
    get { return m_status; }
    set { m_status= value; }
    }
    public string statusname
    {
    get { return _statusname; }
    set { _statusname = value; }
    }

    public int editstatus()
    {
    string[] parameterName = new string[2];
    parameterName[0] = "@statusname";
    parameterName[1] = "@status1";

    SqlDbType[] parameterType = new SqlDbType[7];
    parameterType[0] = SqlDbType.VarChar;
    parameterType[1] = SqlDbType.Bit;
    parameterValue[4] = statusname.CompareTo("") == 0 ? null : statusname;
    parameterValue[5] = status1== null ? null : status1.ToString();

    int res = dal.ExecuteNonquery(dal.connection, CommandType.StoredProcedure, "editstatus", p);
    return res;
    }



    hope this will help you.

  • #687785
    You need to set the Boolean values as True or False not as "True" or False.

    make sure they are not converted as a string.

    Thanks & Regards
    Anil Kumar Pandey
    Microsoft MVP, DNS MVM


  • This thread is locked for new responses. Please post your comments and questions as a separate thread.
    If required, refer to the URL of this page in your new post.