我有以下查询
public const string UpdateSample =
@"UPDATE subReceivingQC
SET Clerk=@Clerk, Comments=@Comments, CommentsProd=@CommentsProd, MassOff=@MassOff,
PalletID=@PalletID, QCDate=@QCDate, QtyInspected=@QtyInspected, StatusClerk=@StatusClerk,
StatusSupervisor=@StatusSupervisor, Supervisor=@Supervisor, PackOut=@PackOut
WHERE GRV=@GRV AND PalletSeq=@PalletSeq AND SampleNo=@SampleNo";
并使用此代码插入项目
// Update sample
query = DatabaseConstants.UpdateSample;
args = new DynamicParameters();
args.Add("@Clerk", sample.Clerk, DbType.String);
args.Add("@Comments", sample.Comments, DbType.String);
args.Add("@CommentsProd", sample.CommentsProd, DbType.String);
args.Add("@MassOff", sample.MassOff, DbType.String);
args.Add("@PackOut", sample.PackOut, DbType.String);
args.Add("@PalletID", sample.PalletID, DbType.String);
args.Add("@QCDate", sample.QCDate, DbType.Date);
args.Add("@QtyInspected ", sample.QtyInspected, DbType.Decimal);
args.Add("@StatusClerk", sample.StatusClerk, DbType.String);
args.Add("@StatusSupervisor", sample.StatusSupervisor, DbType.String);
args.Add("@Supervisor", sample.Supervisor, DbType.String);
args.Add("@GRV", sample.GRV, DbType.Int64);
args.Add("@PalletSeq", sample.PalletSeq, DbType.Int16);
args.Add("@SampleNo", sample.SampleNo, DbType.Int16);
using (var db = new OleDbConnection(connectionString))
{
output += db.Execute(query, args);
}
现在MassOff
和PackOut
的类型均为 double ,其中两种访问数据类型均如下所示:
奇怪的是,代码对于属性MassOff
来说是完美的,但是在添加PackOut
的行后,我得到了
条件表达式中的数据类型无效
我尝试更改参数DbType.Decimal
和DbType.Double
,但没有区别。
我的查询中没有一个参数的顺序与它们在数据库中出现的顺序相同,所以我认为这不是原因,因为如果没有PackOut
值,我会看到相同的问题。
例如,当我尝试传递这些值时:
MassOff :9.5 PackOut :70.5
它适用于MassOff
,但不适用于PackOut
这怎么可能以上帝的名义?
示例课程
public class Sample :
QCObject, IGriddable
{
private string imagesPath = ConfigurationManager.AppSettings["ImagesPath"];
private string[] columnHeaders;
public string[] ColumnHeaders {
get
{
if(columnHeaders.IsNullOrEmpty())
{
return new string[] { "SampleNo", "Date", /*"QCDate",*/ "StatusClerk", "StatusSupervisor" };
}
else
{
return columnHeaders;
}
}
set { columnHeaders = value; } }
private string rowLinkPrefix;
public string RowLinkPrefix {
get
{
if(string.IsNullOrWhiteSpace(rowLinkPrefix))
{
return $"/receiving/{GRV}/{Pallet.PalletSeq}/";
}
else
{
return rowLinkPrefix;
}
}
set { rowLinkPrefix = value; } }
public bool Selectable { get; } = true;
public Pallet Pallet { get; set; }
// Should be 100 - (massoff/qtinspected) but building this manually
// at the moment due to lack of data integrity
[DisplayName("Pack Out")]
public double PackOut { get; set; }
[DisplayName("Pack Out Percentage")]
public double PackoutPerc { get; set; }
[DisplayName("Percentage")]
public double Perc { get; set; }
[DisplayName("Mass Off")]
public double MassOff { get; set; }
[DisplayName("Production Comments")]
public string CommentsProd { get; set; }
[DisplayName("Technical Comments")]
public string Comments { get; set; }
[DisplayName("Quantity Inspected")]
public double QtyInspected { get; set; }
[DisplayName("Sample Number")]
public int SampleNo { get; set; }
[DisplayName("Status Clerk")]
public string StatusClerk { get; set; }
[DisplayName("Status Supervisor")]
public string StatusSupervisor { get; set; }
[DisplayName("Product Spec")]
public string ProductSpec { get; set; }
[DisplayName("PO Container")]
public string POContainer { get; set; }
public string Supervisor { get; set; }
public string Clerk { get; set; }
// For required db params
public string GRV { get; set; }
public string PalletID { get; set; }
[DisplayName("Pallet")]
public string PalletSeq { get; set; }
[DisplayName("Date")]
[DisplayFormat(DataFormatString = "{0:dd/MM/yyyy}", ApplyFormatInEditMode = true)]
public DateTime QCDate { get; set; }
public string Date { get { return QCDate.ToString("dd/MM/yyyy"); } } // My generic WebGrid solution does not alllow me to change thed ate formats, so use this instead
// Each defect status needs to be saved as a (DB)subQCItems item
public List<QCItem> Defects { get; set; } = new List<QCItem>();
public IEnumerable<string> Users { get; set; } = new List<string>();
public Sample()
{
var access = new Access();
Users = access.GetUsers();
}
public IEnumerable<string> Images
{
get
{
string physicalDir;
var dir = Path.Combine(imagesPath, $@"{Pallet.Grv.GRVNo}\{Pallet.PalletSeq}\{SampleNo}\");
physicalDir = dir;
if (Path.IsPathRooted(dir))
{
physicalDir = dir;
}
else
{
physicalDir = HttpContext.Current.Server.MapPath(dir);
}
if (!Directory.Exists(physicalDir))
Directory.CreateDirectory(physicalDir);
foreach (var filePath in Directory.GetFiles(physicalDir).Where(f => f != null))
{
yield return Path.Combine(dir, Path.GetFileName(filePath));
}
}
}
public void SaveImages(IEnumerable<HttpPostedFileBase> files)
{
foreach (var file in files.Where(f => f != null))
{
var dir = $@"{imagesPath}/{Pallet.Grv.GRVNo}/{Pallet.PalletSeq}/{SampleNo}";
var physicalDir = HttpContext.Current.Server.MapPath(dir);
var imageDirInfo = Directory.CreateDirectory(physicalDir);
var counter = imageDirInfo.EnumerateFiles().Count() + 1;
var path = Path.Combine($@"{physicalDir}", $"{counter}{Path.GetExtension(file.FileName)}");
file.SaveAs(path);
counter++;
}
}
}
答案 0 :(得分:2)
OLEDB忽略参数名称。 int
参数按照它们在switch (cell.getCellType()) {
case BOOLEAN:
// ...
case NUMERIC:
// ...
}
语句中出现的顺序
args.Add