我很难得到前导零。SQLite不保留我准备好的语句中的前导零
我有一个事先准备好的声明,看起来像这样:
SQLiteCommand insertSQL = new SQLiteCommand(@"INSERT INTO Inventory(
AssetTag, Vendor, Device, Attribute, DeviceType, System, Location, OnLoan, Notes, LastModifiedTime, LastModifiedPerson, IsDeleted)
VALUES (@AssetTagParam, @VendorParam, @DeviceParam, @AttributeParam, @DeviceTypeParam, @SystemParam, @LocationParam, @OnLoanParam, @NotesParam, @LastModifiedTimeParam, @LastModifiedPersonParam, @IsDeletedParam)", conn);
问题,往往有前导零为“系统”的字段。它的建成,这条线:
var SystemParam = new SQLiteParameter("@SystemParam", System.Data.DbType.String) { Value = item.System };
如果我输入“0159”成Item.System从拉文本框,在运行时,我没有确认Item.System确实在当时举行的“0159”的值SQL语句正在准备中。这使得我认为这种类型,我把它转换到DB,System.Data.DbType.String,在这里是错误的。使用SQLiteStudio将数据直接输入数据库将保留前导零。
我不确定该从哪里出发。 System.Data.DbType中没有另外一种类型,它是我想要尝试的更高级的文本抽象。我不确定该从哪里出发。我怎样才能保持我的领先零点?
编辑:类型澄清
var AssetTagParam = new SQLiteParameter("@AssetTagParam", System.Data.DbType.Int32) { Value = item.AssetTag };
var VendorParam = new SQLiteParameter("@VendorParam", System.Data.DbType.String) { Value = item.Vendor };
var DeviceParam = new SQLiteParameter("@DeviceParam", System.Data.DbType.String) { Value = item.Device };
var AttributeParam = new SQLiteParameter("@AttributeParam", System.Data.DbType.String) { Value = item.Attribute };
var DeviceTypeParam = new SQLiteParameter("@DeviceTypeParam", System.Data.DbType.String) { Value = item.DeviceType };
var SystemParam = new SQLiteParameter("@SystemParam", System.Data.DbType.String) { Value = item.System };
var LocationParam = new SQLiteParameter("@LocationParam", System.Data.DbType.String) { Value = item.Location };
var OnLoanParam = new SQLiteParameter("@OnLoanParam", System.Data.DbType.Boolean) { Value = item.OnLoan };
var NotesParam = new SQLiteParameter("@NotesParam", System.Data.DbType.String) { Value = item.Notes };
var LastModifiedTimeParam = new SQLiteParameter("@LastModifiedTimeParam", System.Data.DbType.String) { Value = item.LastModifiedTime };
var LastModifiedPersonParam = new SQLiteParameter("@LastModifiedPersonParam", System.Data.DbType.String) { Value = item.LastModifiedPerson };
var IsDeletedParam = new SQLiteParameter("@IsDeletedParam", System.Data.DbType.Boolean) { Value = item.IsDeleted };
在DB侧,所有字段都是除ASSETTAG和由assetid,这是INTS类型字符串。 OnLoan和IsDeleted是BOOLEAN。
了解表格中字段的数据类型会很有帮助。 – STLDeveloper
当然!我将整个准备块添加到原始评论中,并在数据库端澄清了它们的类型。 – mkautzm
“在数据库方面,所有字段都是STRING类型”SQL没有“STRING”数据类型。你的意思是TEXT?数据类型BOOLEAN不存在http://sqlite.org/datatype3.html – leonbloy