title=Request.Form(n)中n值在哪里赋值了?
解决方案 »
- 使用ASP.NET AJAX中的StringBuilder出现的问题
- 跪求高手帮助......
- asp.net中如何获取 验证码 中session值 ,并和输入文本框比较,给出提示
- 在asp.net中使用textbox来显示文件时出现“检测到有潜在危险的 Request.Form值”这样的错误
- asp.net 中 怎样动态设置flash的路径?
- sql查询语句
- 高手帮忙,有关RC2CryptoServiceProvider加密问题
- 抓取网页信息时怎么保存图片到本地?一般用什么方法的?
- datagrid分页:只能显示第一页的数据
- 关于vs2003安装问题“vc软件包未找到或未注册“
- mailto;中的换行问题
- 我下载了vs2003,可是安装的时候提示插入系统必备盘,请问各位应如何解决啊
且注意一下'问题
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
for b=1 to 1//这里都是1不是L
假设代码正常,数据表应如下:
ans title
1 aaa
2 bbb
3 ccc但却变成这样,title这一列的值都是空的。
ans title
1aaa
2bbb
3ccc
{
// 在此处放置用户代码以初始化页面
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就可以自动动态添加颜色(颜色是变化的,种类越多,添加记录数就越多
希望对你有帮助!