SQL Server
A family of Microsoft relational database management and analysis systems for e-commerce, line-of-business, and data warehousing solutions.
14,400 questions
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
Receive this error when running the code below. How do I fix this?
objCommand.CommandText = "UPDATE names2 " &
"SET trn_date1 = @trn_date1, " &
"trn_date2 = @trn_date2, trn_date3 = @trn_date3, trn_date4 = @trn_date4, " &
"trn_date5 = @trn_date5, trn_date6 = @trn_date6, trn_date7 = @trn_date7, " &
"trn_date8 = @trn_date8, trn_date9 = @trn_date9, trn_date10 = @trn_date10, " &
"trn_date11 = @trn_date11, " &
"trn_date12 = @trn_date12, trn_date13 = @trn_date13, trn_date14 = @trn_date14, " &
"trn_date15 = @trn_date15, trn_date16 = @trn_date16, trn_date17 = @trn_date17, " &
"trn_date18 = @trn_date18, trn_date19 = @trn_date19, trn_date20 = @trn_date20 " &
"WHERE account_no = " & strAccount_No
' Custom trainings
objCommand.Parameters.AddWithValue("@trn_date1", datTrn_Date1.EditValue)
objCommand.Parameters.AddWithValue("@trn_date2", datTrn_Date2.EditValue)
objCommand.Parameters.AddWithValue("@trn_date3", datTrn_Date3.EditValue)
objCommand.Parameters.AddWithValue("@trn_date4", datTrn_Date4.EditValue)
objCommand.Parameters.AddWithValue("@trn_date5", datTrn_Date5.EditValue)
objCommand.Parameters.AddWithValue("@trn_date6", datTrn_Date6.EditValue)
objCommand.Parameters.AddWithValue("@trn_date7", datTrn_Date7.EditValue)
objCommand.Parameters.AddWithValue("@trn_date8", datTrn_Date8.EditValue)
objCommand.Parameters.AddWithValue("@trn_date9", datTrn_Date9.EditValue)
objCommand.Parameters.AddWithValue("@trn_date10", datTrn_Date10.EditValue)
objCommand.Parameters.AddWithValue("@trn_date11", datTrn_Date11.EditValue)
objCommand.Parameters.AddWithValue("@trn_date12", datTrn_Date12.EditValue)
objCommand.Parameters.AddWithValue("@trn_date13", datTrn_Date13.EditValue)
objCommand.Parameters.AddWithValue("@trn_date14", datTrn_Date14.EditValue)
objCommand.Parameters.AddWithValue("@trn_date15", datTrn_Date15.EditValue)
objCommand.Parameters.AddWithValue("@trn_date16", datTrn_Date16.EditValue)
objCommand.Parameters.AddWithValue("@trn_date17", datTrn_Date17.EditValue)
objCommand.Parameters.AddWithValue("@trn_date18", datTrn_Date18.EditValue)
objCommand.Parameters.AddWithValue("@trn_date19", datTrn_Date19.EditValue)
objCommand.Parameters.AddWithValue("@trn_date20", datTrn_Date20.EditValue)
Try this:
objCommand.Parameters.AddWithValue("@trn_date9", If(CObj(datTrn_Date9.EditValue), DBNull.Value))
If this approach works for trn_date9, it can be applied for other parameters too.
By the way, the strAccount_No can be parameterized too, esp. if it is a string.