title=Request.Form(n)中n值在哪里赋值了?

解决方案 »

  1.   

    title=Request.Form(n)==>title=Request.Form(i)另外最好把sql串起来,一次execute
    且注意一下'问题
      

  2.   

    for b=1 to 1 //这里检查一下 L还是1 如果是 1 那么 就是一次了
    for i = 1 to Request.Form.Count - 1
    ans=Request.Form(i)
    title=Request.Form(n)
    sql="insert into bbb(ans,title) values ('"&ans&"','"&title&"')"
    conn.execute(sql)
    next
    next
      

  3.   

    n和i都是从表单传递过来的变量
    for b=1 to 1//这里都是1不是L
    假设代码正常,数据表应如下:
    ans     title
    1       aaa
    2       bbb
    3       ccc但却变成这样,title这一列的值都是空的。
    ans     title
    1aaa
    2bbb
    3ccc
      

  4.   

    说明title=Request.Form(n)执行后title值为空呀,查查原因吧
      

  5.   

    private void Page_Load(object sender, System.EventArgs e)
    {
    // 在此处放置用户代码以初始化页面
    if(Page.IsPostBack==false)
    {
    getData();
    getDropDownList();
    }
    } #region Web 窗体设计器生成的代码
    override protected void OnInit(EventArgs e)
    {
    //
    // CODEGEN: 该调用是 ASP.NET Web 窗体设计器所必需的。
    //
    InitializeComponent();
    base.OnInit(e);
    }

    /// <summary>
    /// 设计器支持所需的方法 - 不要使用代码编辑器修改
    /// 此方法的内容。
    /// </summary>
    private void InitializeComponent()
    {    
    this.Button1.Click += new System.EventHandler(this.Button1_Click);
    this.Load += new System.EventHandler(this.Page_Load); }
    #endregion
    private void getData()
    {
    SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["test"]);
    string strSql="select Size ,Color from db_color ";
    SqlDataAdapter mycommand=new SqlDataAdapter(strSql,conn);
    DataSet ds=new DataSet();
    mycommand.Fill(ds,"db_color");
    DataGrid1.DataSource=ds.Tables[0].DefaultView;
    DataGrid1.DataBind();

    }
    private void getDropDownList()
    {
    SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["test"]);
    string strSql="select distinct Color from db_color";
    SqlDataAdapter mycommand=new SqlDataAdapter(strSql,conn);
    DataSet ds=new DataSet();
    mycommand.Fill(ds,"db_color");
    DropDownList1.DataTextField="Color";
    //DropDownList1.DataValueField="ColorID";
    DropDownList1.DataSource=ds.Tables[0].DefaultView;
    DropDownList1.DataBind(); }
    private DataSet getColor() //得到所有的颜色
    {
    SqlConnection conn =new SqlConnection(ConfigurationSettings.AppSettings["test"]);
    conn.Open();
    string strSql="select distinct  Color from db_color";
    SqlDataAdapter mycommand=new SqlDataAdapter(strSql,conn);
    DataSet ds=new DataSet();
    mycommand.Fill(ds,"db_color");
    return ds;
    }

    private void Button1_Click(object sender, System.EventArgs e)//多条记录添加
    {

    DataSet ds=(DataSet)getColor();
    string color;
    for(int i=0;i<ds.Tables[0].Rows.Count;i++) //执行循环
    {
    color=ds.Tables[0].Rows[i]["Color"].ToString();
    SqlConnection conn=new SqlConnection(ConfigurationSettings.AppSettings["test"]);
    conn.Open();
    string strSql="insert into db_color(Size,Color)values(@Size,@Color)";
    SqlCommand mycommand =new SqlCommand(strSql,conn);
    mycommand.Parameters.Add(new SqlParameter("@Size",System.Data.SqlDbType.Char,10));
    mycommand.Parameters["@Size"].Value=TextBox1.Text.ToString().Trim();
    mycommand.Parameters.Add(new SqlParameter("@Color",System.Data.SqlDbType.Char,10));
    mycommand.Parameters["@Color"].Value=color.ToString().Trim(); try
    {
    mycommand.ExecuteNonQuery();
    getData();
    }
    catch(Exception ex)
    {
    string s=ex.Message;
    }
    finally
    {
    conn.Close();
    }

    }


    }
    }
    }
    以上是刚做的,我一个同学遇到了这个问题,这是两层的,你也可以弄成三层的,目的就是当你添加衣服大小时,同时把所有的衣服颜色也对应的添加
    M   红色
    M   黄色
    M   黑色
    这种效果,只要输入M就可以自动动态添加颜色(颜色是变化的,种类越多,添加记录数就越多
    希望对你有帮助!