在表现层使用DetailView的插入数据的时候,提示:错误 3 类型“string”必须是不可为 null 的值类型才能用作泛型类型或方法“System.Nullable<T>”中的参数“T” E:\asp.net 2.0\aa\WebSite2\App_Code\BLL\calBLL.cs 69 21 E:\...\WebSite2\
我的数据表名称:calMainRecords
数据表结构及其数据类型:
ID char(6) 不容许空
Equipment_Name varchar(50) 容许空
Use_Place_ID int 不容许空
Cal_Date datetime 不容许空
Due_Date datetime 不容许空
Cal_Cycle_ID int 不容许空
Vender varchar(50) 容许空
Brand varchar(50) 容许空
Model varchar(50) 容许空
Serial_NO varchar(50) 容许空
Accuracy varchar(50) 容许空
Class char(1) 不容许空
Project_ID int 不容许空
Process_ID int 不容许空
Status char(1) 不容许空
WI_NO char(12) 不容许空
Drawing_NO char(12) 容许空
Renter_ID int 容许空
Rent_Date datetime 容许空
Sign_ID int 不容许空
Remark varchar(255) 容许空
我写的方法:
[System.ComponentModel.DataObjectMethodAttribute(System.ComponentModel.DataObjectMethodType.Insert, true)]
public bool AddcalMainRecords(string myEquipment_Name,DateTime? myCal_Date, DateTime? myDue_Date,string myVender, string myBrand, string myModel, string mySerial_NO, string myAccuracy, string? myClass,string? myStatus, string? myWI_NO, string myDrawing_NO,string myRemark,int myID)
{
// 新建一个calMainRecordsRow实例
cal.calMainRecordsDataTable mycals=new cal.calMainRecordsDataTable();
cal.calMainRecordsRow mycal=mycals.NewcalMainRecordsRow();
//mycal.Equipment_Name = myEquipment_Name.ToString();
if (myEquipment_Name == null) mycal.SetEquipment_NameNull(); else mycal.Equipment_Name = myEquipment_Name.ToString();
if (myVender == null) mycal.SetVenderNull(); else mycal.Vender = myVender.ToString();
if (myBrand == null) mycal.SetBrandNull(); else mycal.Brand = myBrand.ToString();
if (myModel == null) mycal.SetModelNull(); else mycal.Equipment_Name = myEquipment_Name.ToString();
if (mySerial_NO == null) mycal.SetSerial_NONull(); else mycal.Serial_NO = mySerial_NO.ToString();
if (myAccuracy == null) mycal.SetAccuracyNull(); else mycal.Accuracy = myAccuracy.ToString();
if (myDrawing_NO == null) mycal.SetDrawing_NONull(); else mycal.Drawing_NO = myDrawing_NO.ToString();
//少了Renter_ID和Rent_Date
if (myRemark == null) mycal.SetRemarkNull(); else mycal.Remark = myRemark.ToString();
mycals.AddcalMainRecordsRow(mycal);
int rowsAffected = Adapter.Update(mycals);
// 如果刚好新增了一条记录,则返回true,否则返回false
return rowsAffected == 1;
}
------解决方案--------------------------------------------------------
http://www.phpfans.net/article/htmls/201012/MzIyMTg2
http://hi.baidu.com/cxl_goto/blog/item/aabb09d7b9f9efd5a044df02
------解决方案--------------------------------------------------------
帮顶。。。。
------解决方案--------------------------------------------------------
if (myVender == null) 改为if ( string.IsNullOrEmpty(myVender))
------解决方案--------------------------------------------------------