本文介绍了将DataTimePicker插入数据库sql server的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述 29岁程序员,3月因学历无情被辞! 这是使用datatimepicker字段取消更新Sql表的正确语句 我正在使用此代码传递参数 CMD.CommandText = QueryI CMD.Parameters.AddWithValue(" @ Codice",row.Field(Of String)(") ; ClienteCodice")) CMD.Parameters.AddWithValue(" @ RagSoc",row.Field(Of String)(" ClienteRagSoc")) CMD.Parameters.AddWithValue(" @ Citta" ,row.Field(Of String)(" ClienteCitta")) CMD.Parameters.AddWithValue(" @ Provincia",row.Field(Of String)(" ClienteProvincia")) CMD .Parameters.AddWithValue(" @ DataCreazione",row.Field(Of DatetimePicker)(" ClienteDataCreazione")) CMD.Parameters.AddWithValue(" @ Importo",row.Field(Of String)(") ; ClienteImporto")) 解决方案 代码l好的,查询应该看起来像这样,使用ExecuteScalar来获取新的主键 Dim insertStatement As String = < SQL> INSERT INTO dbo.Orders ( CustomerIdentifier, EmployeeID, OrderDate )VALUES ( @CustomerIdentifier, @EmployeeID, @OrderDate ); SELECT CAST(scope_identity()AS int); < / SQL> .Value 仅通过ExecuteNonQuery插入 Dim insertStatement As String = < SQL> INSERT INTO dbo.Orders ( CustomerIdentifier, EmployeeID, OrderDate )VALUES ( @CustomerIdentifier, @EmployeeID, @OrderDate ); < / SQL> .Value which is the correct statement to unpdate a Sql table with a datatimepicker fieldI'm using this code to pass parametersCMD.CommandText = QueryICMD.Parameters.AddWithValue("@Codice", row.Field(Of String)("ClienteCodice"))CMD.Parameters.AddWithValue("@RagSoc", row.Field(Of String)("ClienteRagSoc")) CMD.Parameters.AddWithValue("@Citta", row.Field(Of String)("ClienteCitta"))CMD.Parameters.AddWithValue("@Provincia", row.Field(Of String)("ClienteProvincia")) CMD.Parameters.AddWithValue("@DataCreazione", row.Field(Of DatetimePicker)("ClienteDataCreazione")) CMD.Parameters.AddWithValue("@Importo", row.Field(Of String)("ClienteImporto")) 解决方案 Well the code look okay, the query should look like this with an ExecuteScalar to get the new primary keyDim insertStatement As String = <SQL> INSERT INTO dbo.Orders ( CustomerIdentifier, EmployeeID, OrderDate ) VALUES ( @CustomerIdentifier, @EmployeeID, @OrderDate ); SELECT CAST(scope_identity() AS int); </SQL>.ValueInsert only via ExecuteNonQueryDim insertStatement As String = <SQL> INSERT INTO dbo.Orders ( CustomerIdentifier, EmployeeID, OrderDate ) VALUES ( @CustomerIdentifier, @EmployeeID, @OrderDate ); </SQL>.Value 这篇关于将DataTimePicker插入数据库sql server的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持! 上岸,阿里云! 08-29 20:19