按照微软件的PetShop的例子,一个表可以定义一个类,如
public class LineItemInfo { // Internal member variables
private string _id;
private string _productName;
private int _line;
private int _quantity;
private decimal _price;
public LineItemInfo(){} /// <summary>
/// Constructor with specified initial values
/// </summary>
/// <param name="id">Item Id</param>
/// <param name="line">Line number</param>
/// <param name="qty">Quanity in order</param>
/// <param name="price">Order item price</param>
public LineItemInfo(string id, string name, int line, int qty, decimal price){
this._id = id;
this._productName = name;
this._line = line;
this._price = price;
this._quantity = qty;
} // Properties
public string ItemId {
get { return _id; }
set { _id = value; }
} public string Name {
get { return _productName; }
set { _productName = value; }
} public int Line {
get { return _line; }
set { _line = value; }
} public int Quantity {
get { return _quantity; }
set { _quantity = value; }
} public decimal Price {
get { return _price; }
set { _price = value; }
} public decimal SubTotal {
get { return _price * _quantity; }
}
}操作的时间,可以这么写
itemParms[0].Value = item.Line;
itemParms[1].Value = item.ItemId;
itemParms[2].Value = item.Quantity;
itemParms[3].Value = item.Price;
现在存在点问题,如果给某个字段赋空值如何处理,前台传过来的是一个LineItemInfo 变量,它的整型属性没法赋成null。

解决方案 »

  1.   

    这个涉及到预先定义空值的问题  以前有想过
     就比如说整型 中 哪个为空 0,-1, 还是 NULL?  当然这个NULL好象是没有的 又或者是 时间类型中的哪个时间是空? 0001 01 01么? 
     这都是需要定义的
      

  2.   

    这个问题我很早就注意到了,上网找了一下,没有什么太好的解决方法,只能你有可能是Null值的时候提前判断!这样代码就看起来很不爽!
      

  3.   

    关注~~~~~~~~~~!!我也遇到同样问题,
    比如说一个很常见的例子,
    我需要向数据库里插入一笔纪录,但表中含有一个自动增加的int列。
    这样我该如何向属性中传递空值呢?????
    难道真没有好的解决办法????听楼下的~~~~~~~~~