要插入的表结构是:除了主键外,其他属性均可为空。
插入方法:
public bool Insert(MMember mMember)
{
string sqlText = "Insert Into MemberS (MemberID,MemberName,Sex,company,Mobile,Phone,Fax,Address,MemberType,PayType,BankCard,BankName,Memo,BankTime)"
+ " Values(:MemberID,:MemberName,:Sex,:Company,:Mobile,:Phone,:Fax,:Address,:MemberType,:PayType,:BankCard,:BankName,:Memo,:BankTime)";
OracleParameter[] parms = new OracleParameter[]
{
new OracleParameter("MemberID", OracleType.VarChar),
new OracleParameter("MemberName", OracleType.NVarChar),
new OracleParameter("Sex", OracleType.NVarChar),
new OracleParameter("Company", OracleType.NVarChar),
new OracleParameter("Mobile", OracleType.VarChar),
new OracleParameter("Phone", OracleType.VarChar),
new OracleParameter("Fax", OracleType.VarChar),
new OracleParameter("Address", OracleType.NVarChar),
new OracleParameter("MemberType", OracleType.NVarChar),
new OracleParameter("PayType", OracleType.NVarChar),
new OracleParameter("BankCard", OracleType.VarChar),
new OracleParameter("BankName", OracleType.NVarChar),
new OracleParameter("Memo", OracleType.NVarChar),
new OracleParameter("BankTime", OracleType.Timestamp)
};
parms[0].Value = mMember.MemberID;
parms[1].Value = mMember.MemberName;
parms[2].Value = mMember.Sex;
parms[3].Value = mMember.Company;
parms[4].Value = mMember.Mobile;
parms[5].Value = mMember.Phone;
parms[6].Value = mMember.Fax;
parms[7].Value = mMember.Address;
parms[8].Value = mMember.MemberType;
parms[9].Value = mMember.PayType;
parms[10].Value = mMember.BankCard;
parms[11].Value = mMember.BankName;
parms[12].Value = mMember.Memo;
if (string.IsNullOrEmpty(mMember.BankCard))
{
parms[13].Value = null;
}
else
{
parms[13].Value = DateTime.Now;
}
CacheUtility.RemoveCache(0, "Members");
int rowsAffected = 0;
try
{
rowsAffected = OracleHelper.ExecuteNonQuery(OracleHelper.Connection_String, CommandType.Text, sqlText, parms);//执行语句
}
catch (Exception ex)
{
return false;
}
return rowsAffected > 0;
}
调用的时候只对 MemberID = memId,
MemberName=memName,
Phone=memPhone,
Mobile=memMobile,
MDate=DateTime.Now这五个属性进行了赋值,其他的没赋值。
按说其他属性允许为空的,插入的时候为什么还提示“ORA-01008: 并非所有变量都已绑定”??
在对象引用类型的属性没有赋值的情况下,值为 null
将 null 赋予参数对象的 value 属性,相当于没有赋值,所以 Oracle 报 ORA-01008: 并非所有变量都已绑定
对于准备赋予数据库 null 的参数应该明确赋予 DBNull