1

我有一个带有值的表格

           Price  <input type="text" name="items[price]" value="" /> <br />
       Condition  <input type="text" name="items[condition]" value="" /> <br />
           Brand  <input type="text" name="items[brand]" value="" /> <br />

我想将此发送到数据库

    string[] allitems = Request.Form["items"];
    var db2x = Database.Open("mystring");

    foreach (var item in allitems)
    {
       var insertCommand2x = "INSERT INTO Classifieds_attr_value (AttrId,CarBikeId,AttrVal) VALUES(@0,@1,@2)";
       db2x.Execute(insertCommand2x, AttrId, CarBikeId, AttrVal);

   }

这不起作用请帮助

4

1 回答 1

4

您应该必须items对所有值使用值并通过方法input读取值。Request.Form.GetValues("items")

Price      <input type="text" name="items" value="" /> <br />
Condition  <input type="text" name="items" value="" /> <br />
Brand      <input type="text" name="items" value="" /> <br />

并读取值,

string []items=Request.Form.GetValues("items");
if(items!=null){
   //read
}

或者为名称属性选择不同的值。

Price      <input type="text" name="price" value="" /> <br />
Condition  <input type="text" name="condition" value="" /> <br />
Brand      <input type="text" name="brand" value="" /> <br />

并读取键值,

string[] keys = Request.Form.AllKeys;
if (keys!= null)
 {
  foreach (var key in keys)
   {
   Response.Write("<br/>" + key + " " + Request.Form[key]);
   }
 }
于 2012-09-16T04:55:37.147 回答