c# access插入null值

c# 插入access数据库

提示错误:

Parameter @DeviceLocation has no default value. 参数@DeviceLocation 的有没有默认值。

StringBuilder strSql = new StringBuilder();
            strSql.Append("insert into Device(");
            strSql.Append("DeviceLocation,Remark)");
            strSql.Append(" values (");
            strSql.Append("@DeviceLocation,@Remark)");
OleDbParameter[] parameters = {
                    new OleDbParameter("@DeviceLocation", OleDbType.VarChar,255),
new OleDbParameter("@Remark", OleDbType.VarChar,255)};
            parameters[0].Value = string.IsNullOrEmpty(model.DeviceLocation)  ? DBNull.Value.ToString() : model.DeviceLocation;
            parameters[1].Value = string.IsNullOrEmpty(model.Remark) ? DBNull.Value.ToString() : model.Remark; 

int rows = DbHelperOleDb.ExecuteSql(strSql.ToString(), parameters);

设定值为 DBNull.Value

原文地址:https://www.cnblogs.com/z_lb/p/3156537.html