How do I fix this parameterized query error?

SuperCoder 196 Reputation points
2025-01-29T17:09:58.67+00:00

Receive this error when running the code below. How do I fix this?

User's image

 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)

SQL Server
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
VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,775 questions
{count} votes

Accepted answer
  1. Viorel 119.3K Reputation points
    2025-01-29T18:07:30.0766667+00:00

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.