我在做文章系统时,在文章发布功能这模块的时候,有个问题不知道怎么解决。我发表文章时,可以选择是否添加图片。选择“是”就添加到数据库,选择“否”就不添加。但我选择“否”的时候,提交文章的时候却报错说过程 'AddArticle' 需要参数 '@photo',但未提供该参数。现我给出我的程序给大家看下:存储过程:
alter proc AddArticle
(
@title varchar(100),
@show int,
@photo image,
@compose_date smalldatetime
)
AS
if exists(select * from [Article] where title=@title)
return 0   ----该文章已存在
insert into [Article](title,show,photo,compose_date) 
values (@title,@show,@photo,@compose_date)
return 1 ---添加成功
GO=====================
ASPX:
<tr class="left_title_2">
          <td>首页图片:</td>
          <td align="left"><input type="radio" name="show" id="show0" value="0" runat="server" onClick="div2.style.display='none'"  />不显示 
            <input type="radio" name="show" id="show" value="1" runat="server" onClick="div2.style.display=''"  />显示 </td>
        </tr><div id="div2" style="display:none"><asp:FileUpload ID="photo" runat="server" Width="150px" /></div>=========================
CS:
 if(show.Checked)
            {
                _art.show = Convert.ToInt32(show.Value);
                _art.photo = Common.Fun.FileToByte(photo.PostedFile.FileName); //将图片转换为字节流
            }
            else
            {
                _art.show = Convert.ToInt32(show0.Value);
            }
问题我知道是_art.photo没有值。应该怎么解决呢

解决方案 »

  1.   


    if(show.Checked) 
                { 
                    _art.show = Convert.ToInt32(show.Value); 
                    _art.photo = Common.Fun.FileToByte(photo.PostedFile.FileName); //将图片转换为字节流 
                } 
                else 
                { 
                    _art.show = Convert.ToInt32(show0.Value); 
                    _art.photo = null;
                } 
      

  2.   

    我之前试过了,也不行。
    报错说:
    过程 'AddArticle' 需要参数 '@photo',但未提供该参数。我现在这样弄了下:
    if(show.Checked)
    {
     _art.show = Convert.ToInt32(show.Value);
    _art.photo = Common.Fun.FileToByte(photo.PostedFile.FileName); //将图片转换为字节流
    }
    else
    {
    _art.show = Convert.ToInt32(show0.Value);
      //暂时没有想到好的方法,先用一张图片顶着先           
    _art.photo = Common.Fun.FileToByte(Server.MapPath("\\web\\images\\index_06.gif"));
      

  3.   

    写多了:     不是源代码来的。===================if(show.Checked)
                {
                    _art.show = Convert.ToInt32(show.Value);
                    _art.photo = Common.Fun.FileToByte(photo.PostedFile.FileName); //将图片转换为字节流
                }
                else
                {
                    _art.show = Convert.ToInt32(show0.Value);
                   _art.photo = Common.Fun.FileToByte(Server.MapPath("\\web\\images\\index_06.gif")); //暂时没有想到好的方法,先用一张图片顶着先
                }