try{Convert.ToInt16(TextBox7.Text.ToString());}
catch(Exception e){MessageBox.ShowDialog(e.Message);}

解决方案 »

  1.   

    这样的语句中怎么加try语句呢myCMD.Parameters["@所在楼层"].Value=Convert.ToInt16(TextBox7.Text.ToString());
      

  2.   

    myCMD.Parameters["@所在楼层"].Value=Convert.ToInt16(TextBox7.Text.ToString());
    改为:
    int txt7;
    try
    {
        txt7=Convert.ToInt16(TextBox7.Text.ToString());
        myCMD.Parameters["@所在楼层"].Value=txt7;
    }
    catch(Exception)
    {
         //windows form:MessageBox.Show("Wrong Char");
         //Web Form:Response.Write("<script>alert('Wrong Char');</script>");
    }
      

  3.   

    if(null!=TextBox7.Text)
    Convert.ToInt16(TextBox7.Text.ToString());