我试图使用msoledbsql提供程序和数据集向表中添加新行。但是在调用更新函数时,我遇到了异常:
提供的时间值的小数部分会溢出相应SQL Server参数或列的小数位数。增加DBPARAMBINDINFO中的bScale或列规模以纠正此错误
如何解决此问题?
Private oRunDefDS As DataSet
oRunDefDS.Clear()
' create the Data Row
Dim oDR As DataRow = oRunDefDS.Tables("RunDef").NewRow()
' populate the datarow with values
AddDRofRunDef(RunDef, oDR)
' add the datarow to the dataset
oRunDefDS.Tables("RunDef").Rows.Add(oDR)
Private Sub AddDRofRunDef(ByVal RunDef As DBResults, ByRef oDR As DataRow)
' Add a new row to Dataset from a class object.
' Copy Results definition for a particular RunID
' from DBResults Class to RunDef table of database ProductionResults.
With RunDef
oDR("RunId") = 10
oDR("RunDateTime") = .RunDateTime
oDR("LineNum") = .LineNum
oDR("ProductID") = .ProductID
oDR("RunNum") = .RunNum
oDR("ActNumWires") = .ActNumWires
oDR("OWOWSpec") = .OWOWSpec
oDR("OWOWTolUpper") = .OWOWTolUpper
oDR("OWOWTolLower") = .OWOWTolLower
oDR("OperID") = .OperID
oDR("SampleOffset") = .SampleOffset
oDR("Blank1") = 1
oDR("Blank2") = 2
oDR("Blank3") = 3
oDR("Blank4") = 4
End With
End Sub
答案 0 :(得分:2)
如果您不想更改列的比例,而是删除数据的小数部分,则可以使用以下两种方法:
Public Function Truncate(source As Date) As Date
With source
Return New Date(.Year, .Month, .Day, .Hour, .Minute, .Second)
End With
End Function
Public Function Truncate(source As TimeSpan) As TimeSpan
With source
Return New TimeSpan(.Days, .Hours, .Minutes, .Seconds)
End With
End Function
如果愿意,您甚至可以将其编写为扩展方法:
Public Module DateTimeExtensions
<Extension>
Public Function Truncate(source As Date) As Date
With source
Return New Date(.Year, .Month, .Day, .Hour, .Minute, .Second)
End With
End Function
End Module
Public Module TimeSpanExtensions
<Extension>
Public Function Truncate(source As TimeSpan) As TimeSpan
With source
Return New TimeSpan(.Days, .Hours, .Minutes, .Seconds)
End With
End Function
End Module
,然后直接在该类型的值上调用它们,例如
With RunDef
oDR("RunId") = 10
oDR("RunDateTime") = .RunDateTime.Truncate()