CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
可用分押宝游戏火热进行中... 专题改版:Java Web 专题
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  .NET技术 >  ASP.NET

指定的转换无效。

楼主zitiger(MSN聊天机器人:RobotBB001@hotmail.com)2003-05-04 11:36:17 在 .NET技术 / ASP.NET 提问

 
  指定的转换无效。  
  错误提示  
  “/NetAlbum”应用程序中的服务器错误。  
  --------------------------------------------------------------------------------  
   
  指定的转换无效。    
  说明:   执行当前   Web   请求期间,出现未处理的异常。请检查堆栈跟踪信息,以了解有关该错误以及代码中导致错误的出处的详细信息。    
   
  异常详细信息:   System.InvalidCastException:   指定的转换无效。  
   
  源错误:    
   
   
  行   141:  
  行   142: //   Calculate   the   CustomerID   using   Output   Param   from   SPROC  
  行   143: int   Id   =   (int)parameterR.Value;  
  行   144:  
  行   145: return   Id;  
     
   
  源文件:   c:\documents   and   settings\administrator\桌面\asp.net\netalbum\components\school.cs         行:   143    
   
  堆栈跟踪:    
   
   
  [InvalidCastException:   指定的转换无效。]  
        NetAlbum.School.AddSchool(Int32   MId,   String   SchoolName,   Int32   Type)   in   c:\documents   and   settings\administrator\桌面\asp.net\netalbum\components\school.cs:143  
        NetAlbum.SchoolList.Button1_Click(Object   sender,   EventArgs   e)   in   c:\documents   and   settings\administrator\桌面\asp.net\netalbum\school.aspx.cs:174  
        System.Web.UI.WebControls.Button.OnClick(EventArgs   e)   +108  
        System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String   eventArgument)   +57  
        System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler   sourceControl,   String   eventArgument)   +18  
        System.Web.UI.Page.RaisePostBackEvent(NameValueCollection   postData)   +33  
        System.Web.UI.Page.ProcessRequestMain()   +1263  
   
     
   
   
  --------------------------------------------------------------------------------  
  版本信息:   Microsoft   .NET   框架版本:1.0.3705.0;   ASP.NET   版本:1.0.3705.0    
   
   
   
  Code  
  <table   class="EmptyTable"   id="Table2"   style="BORDER-COLLAPSE:   collapse"   cellPadding="0"   width="100%"   BcellSpacing="0">  
      <tr>  
          <td   class="TableTop"   vAlign="bottom"   align="middle"   height="18">  
          <img   src="images/Default/bullet.gif">   增   加   学   校</td>  
      </tr>  
      <tr>  
          <td   vAlign="top"   height="100">  
          <table   border="0"   cellpadding="0"   cellspacing="0"   style="BORDER-COLLAPSE:   collapse"   height="100">  
              <tr>  
                  <td   height="6"   colspan="3"></td>  
              </tr>  
              <tr>  
                  <td   width="60"   height="35"   align="right">学校名称</td>  
                  <td   width="10"   height="35"></td>  
                  <td   width="130"   height="35">  
                  <asp:TextBox   id="SchoolName"   runat="server"   Width="100px"></asp:TextBox>  
                  </td>  
              </tr>  
              <tr>  
                  <td   width="60"   height="35"   align="right">学校种类   </td>  
                  <td   width="10"   height="35"></td>  
                  <td   width="130"   height="35">  
                  <select   id="Type"   style="FONT-SIZE:   9pt"   size="1"   name="Type"   runat="server">  
                  <option   value="请选择">请选择</option>  
                  <option   value="1">小学</option>  
                  <option   value="2"   selected>初中</option>  
                  <option   value="3">中专</option>  
                  <option   value="4">高中</option>  
                  <option   value="5">大学</option>  
                  <option   value="0">其他</option>  
                  </select>   </td>  
              </tr>  
              <tr>  
                  <td   colspan="3"   height="24"   align="middle">  
                  <asp:Button   id="Button1"   runat="server"   CssClass="Button"   Text="增加">  
                  </asp:Button>  
                  </td>  
              </tr>  
              <tr>  
                  <td   colspan="3"   height="6"></td>  
              </tr>  
          </table>  
          </td>  
      </tr>  
  </table>  
   
  存储过程  
   
  CREATE   Procedure   AddSchool  
  @MId Int,  
  @SchoolName nvarchar(20),  
  @Type int,  
  @R INT   OUTPUT  
  AS  
   
  SELECT  
  [Id]  
  FROM  
  School  
  WHERE    
  MunicipalId=@MId  
  AND  
  SchoolName=@SchoolName  
  IF   @@ROWCOUNT<1  
  SELECT   R=0  
  ELSE  
  BEGIN  
  INSERT   INTO   School  
  (  
  MunicipalId,  
  SchoolName,  
  Type  
  )  
  VALUES  
  (  
  @MId,  
  @SchoolName,  
  @Type  
  )  
  SELECT   @R=1  
  END  
  GO  
   
   
  CodeBehind  
   
   
                  private   void   Button1_Click(object   sender,   System.EventArgs   e)  
                  {  
                          if(SchoolName.Text=="")  
                          {  
                                  FS   Fail=new   FS();  
                                  Fail.FHtml("","必须填写学校名称!");  
                          }  
                          if(SchoolName.Text.Length>20||SchoolName.Text.Length<5)  
                          {  
                                  FS   Fail=new   FS();  
                                  Fail.FHtml("","学校名称长度不能小于5位,大于20位!");  
                          }  
                          School   MySchool=new   School();  
                          int   R=MySchool.AddSchool(int.Parse(Request.QueryString["Id"]),SchoolName.Text,int.Parse(Type.Value));  
                   
                  }  
                   
          public   class   School  
          {  
                  public   int   AddSchool(int   MId,string   SchoolName,int   Type)    
                  {  
   
                          //   Create   Instance   of   Connection   and   Command   Object  
                          SqlConnection   myConnection   =   new   SqlConnection(ConfigurationSettings.AppSettings["ConnectionString"]);  
                          SqlCommand   myCommand   =   new   SqlCommand("AddSchool",   myConnection);  
   
                          //   Mark   the   Command   as   a   SPROC  
                          myCommand.CommandType   =   CommandType.StoredProcedure;  
   
                          //   Add   Parameters   to   SPROC  
                          SqlParameter   parameterMId   =   new   SqlParameter("@MId",   SqlDbType.Int,4);  
                          parameterMId.Value   =   MId;  
                          myCommand.Parameters.Add(parameterMId);  
   
                          SqlParameter   parameterSchoolName   =   new   SqlParameter("@SchoolName",   SqlDbType.NVarChar,   20);  
                          parameterSchoolName.Value   =   SchoolName;  
                          myCommand.Parameters.Add(parameterSchoolName);  
   
                          SqlParameter   parameterType   =   new   SqlParameter("@Type",   SqlDbType.Int,4);  
                          parameterType.Value   =   Type;  
                          myCommand.Parameters.Add(parameterType);  
   
                          SqlParameter   parameterR   =   new   SqlParameter("@R",   SqlDbType.Int,   4);  
                          parameterR.Direction   =   ParameterDirection.Output;  
                          myCommand.Parameters.Add(parameterR);  
   
                          myConnection.Open();  
                          myCommand.ExecuteNonQuery();  
                          myConnection.Close();  
   
                          //   Calculate   the   CustomerID   using   Output   Param   from   SPROC  
                          int   Id   =   (int)parameterR.Value;  
   
                          return   Id;  
   
                  }  
          }  
  问题点数:20、回复次数:3Top

1 楼zitiger(MSN聊天机器人:RobotBB001@hotmail.com)回复于 2003-05-04 11:45:00 得分 0

upTop

2 楼saucer(思归)回复于 2003-05-04 11:52:30 得分 20

are   you   sure   your   stored   procedure   is   valid??  
   
  SELECT   R=0  
  ^^^^^^^^^^^^^^  
  ===>  
  SET   @R   =   0Top

相关问题

  • 指定的转换无效
  • "指定的转换无效"怎么办?
  • DataLish发生指定的转换无效
  • 指定的转换无效。求助
  • 请教:System.InvalidCastException: 指定的转换无效。
  • 无法更新 DataGrid中数据?指定的转换无效,
  • 在用DataGrid1_UpdateCommand的时候,总提示“指定的转换无效”
  • 求解:“System.Exception: 指定的转换无效”谢谢。
  • 100分,小问题-----指定的转换无效
  • datagrid指定的转换无效啊???郁闷啊

关键词

  • asp.net
  • 转换
  • 桌面
  • asp
  • netalbum
  • 错误
  • school
  • 指定的转换无效
  • ui
  • administrator

得分解答快速导航

  • 帖主:zitiger
  • saucer

相关链接

  • CSDN .NET频道
  • .NET类图书
  • C#类图书
  • .NET类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
世纪乐知(北京)网络技术有限公司 版权所有, 京 ICP 证 020026 号
北京创新乐知广告有限公司 提供技术支持
Copyright © 2000-2007, CSDN.NET, All Rights Reserved
GongshangLogo