OleDBAdapter - error on ExecuteNonQuery

  • Thread starter Thread starter Tersia Ehlert
  • Start date Start date
T

Tersia Ehlert

Hi

New in ADO.NET

I get an error "Must declare the variable '@pLastWorkingDay'." when my code
gets to "lrstResign.UpdateCommand.ExecuteNonQuery()"

What is missing?

See code below:

Dim lcnnVision As New System.Data.OleDb.OleDbConnection

Dim lcmdVision As New System.Data.OleDb.OleDbCommand

Dim lrstResign As New System.Data.OleDb.OleDbDataAdapter

lcnnVision.ConnectionString = lstrConnectionStringVision

lcnnVision.Open()

lcmdVision.Connection = lcnnVision

lcmdVision.CommandText = "Update Employees SET emTermDate=@pLastWorkingDay
WHERE [emEmployeeCode] = '" & txtVisionCode.Text & "'"

Dim paramLastWorkingDay As New System.Data.OleDb.OleDbParameter

paramLastWorkingDay.ParameterName = "pLastWorkingDay"

paramLastWorkingDay.OleDbType = OleDb.OleDbType.DBDate

paramLastWorkingDay.Value = K2calLastWorkingDay.SelectedDate

lcmdVision.Parameters.Add(paramLastWorkingDay)

lrstResign.UpdateCommand = lcmdVision



lrstResign.UpdateCommand.ExecuteNonQuery()
 
Try changing this line paramLastWorkingDay.ParameterName = "pLastWorkingDay"
to "@pLastWorkingDay"
 
Thanks - that helped.

2 changes made - success:
1. "pLastWorkingDay" to "@pLastWorkingDay"
2. Change the oledb stuff to sqlclient

William Ryan said:
Try changing this line paramLastWorkingDay.ParameterName = "pLastWorkingDay"
to "@pLastWorkingDay"
Tersia Ehlert said:
Hi

New in ADO.NET

I get an error "Must declare the variable '@pLastWorkingDay'." when my code
gets to "lrstResign.UpdateCommand.ExecuteNonQuery()"

What is missing?

See code below:

Dim lcnnVision As New System.Data.OleDb.OleDbConnection

Dim lcmdVision As New System.Data.OleDb.OleDbCommand

Dim lrstResign As New System.Data.OleDb.OleDbDataAdapter

lcnnVision.ConnectionString = lstrConnectionStringVision

lcnnVision.Open()

lcmdVision.Connection = lcnnVision

lcmdVision.CommandText = "Update Employees SET emTermDate=@pLastWorkingDay
WHERE [emEmployeeCode] = '" & txtVisionCode.Text & "'"

Dim paramLastWorkingDay As New System.Data.OleDb.OleDbParameter

paramLastWorkingDay.ParameterName = "pLastWorkingDay"

paramLastWorkingDay.OleDbType = OleDb.OleDbType.DBDate

paramLastWorkingDay.Value = K2calLastWorkingDay.SelectedDate

lcmdVision.Parameters.Add(paramLastWorkingDay)

lrstResign.UpdateCommand = lcmdVision



lrstResign.UpdateCommand.ExecuteNonQuery()
 
Back
Top