首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > asp.net >

大家帮我看看这到底是如何回事,如何老是提示'必须输入参数@title',可是已经有了呀

2011-12-22 
大家帮我看看这到底是怎么回事,怎么老是提示必须输入参数@title,可是已经有了呀SqlDataSource:asp:SqlD

大家帮我看看这到底是怎么回事,怎么老是提示'必须输入参数@title',可是已经有了呀
SqlDataSource   :
<asp:SqlDataSource   ID= "SqlDataSource1 "   runat= "server "   DataSourceMode=DataSet     ProviderName= "System.Data.SqlClient "   ConnectionString= " <%$   ConnectionStrings:wwwConnectionString   %> "
                        SelectCommand= "SELECT   *   FROM   [Student]   ORDER   BY   [id]   desc "                            
                            DeleteCommand= "delete   from   Student   where   id=@id "                        
                        >
                        <DeleteParameters>
                              <asp:Parameter   Name= "id "     Type=Int32/>
                        </DeleteParameters>
                </asp:SqlDataSource>
gridview1:
  DataSourceID= "SqlDataSource1 ",DataKeyNames= "id "
<FooterTemplate>
                                                <asp:Button   ID= "Button3 "   runat= "server "   Text= "添加 "   CommandName= "add "   CausesValidation= "False "   OnClick= "add_Click "/>
                                        </FooterTemplate>
protected   void   add_Click(object   sender,   EventArgs   e)
        {
                string   dtime   =   ((TextBox)GridView1.FooterRow.FindControl( "new_BirthDay ")).Text;
                string   title   =   ((TextBox)GridView1.FooterRow.FindControl( "new_title ")).Text;
                int   gender=((RadioButtonList)GridView1.FooterRow.FindControl( "new_gender ")).SelectedValue   ==   "男 "?1:0;    
              string   clsname   =   ((DropDownList)GridView1.FooterRow.FindControl( "new_classname ")).SelectedValue;
                FileUpload   fil   =   (FileUpload)GridView1.FooterRow.FindControl( "addphoto ");
                string   filename   =   " ";
                filename   =   Guid.NewGuid().ToString( "D ")   +   System.IO.Path.GetExtension(fil.FileName);
                fil.SaveAs(Server.MapPath( "~/images/Upload/ ")   +   filename);
                string   sql   =   "insert   into   Student(Title,BirthDay,Gender,PhotoPath,ClassName)values(@Title,@BirthDay,@Gender,@PhotoPath,@ClassName) ";


                SqlDataSource1.InsertCommand   =   sql;
                SqlDataSource1.InsertParameters.Add( "@Title ",   TypeCode.String,title);
                SqlDataSource1.InsertParameters.Add( "@BirthDay ",   TypeCode.DateTime,dtime);
                SqlDataSource1.InsertParameters.Add( "@Gender ",   TypeCode.Int32,gender.ToString());
                SqlDataSource1.InsertParameters.Add( "@PhotoPath ",   TypeCode.String,   filename);
                SqlDataSource1.InsertParameters.Add( "@ClassName ",   TypeCode.String,   clsname);
                SqlDataSource1.Insert();                
        }
在gridview中有几个模版列,在FooterTemplate   中放着几个文本框呀什么的,在最后一列的FooterTemplate中有个添加按纽,现在老是提示必须输入参数@title ',Gender为bit类型

[解决办法]
如果是SQL Server系统,使用事件跟踪器看一下执行的SQL就知道是不是真的少了参数了。
[解决办法]
为什么呢?
因为这个参数你传入的其实的一个null值,所以程序会认为没有
你传入一个 " "就可以解决了
[解决办法]
把string sql = "insert into Student(Title,BirthDay,Gender,PhotoPath,ClassName)values(@Title,@BirthDay,@Gender,@PhotoPath,@ClassName) ";
改成
string sql = "insert into Student(Title,BirthDay,Gender,PhotoPath,ClassName)values(?,?,?,?,?) ";

试试看

[解决办法]
SqlDataSource1.InsertParameters.Add( "@Title ", TypeCode.String,title);

---->

string title = ((TextBox)GridView1.FooterRow.FindControl( "new_title ")).Text;


不是不没取到这里的textbox的值??


[解决办法]
大小写?

title ≠Title

热点排行