i use this Update code to update my record but i get this error msg : 

 Dim con As New SqlConnection
        con.ConnectionString = My.Settings.TenderingSysConnectionString

        Dim cmd As SqlCommand = con.CreateCommand()
        cmd.CommandType = CommandType.Text

        cmd.CommandText = "update BOQDetailEntry set BOQDetailEntry_ID=@BOQDetailEntry_ID, ProjectTenderingNO=@ProjectTenderingNO,BOQSection=@BOQSection,Part=@Part,BOQITEM=@BOQITEM,BOQItemNo=@BOQItemNo,Description=@Description,Unit=@Unit,BOQTY=@BOQTY,ReferenceDrawing=@ReferenceDrawing,ReferenceSpecifications=@ReferenceSpecifications where BOQDetailEntry_ID=@BOQDetailEntry_ID"
        ' BOQDetailEntry_ID=@BOQDetailEntry_ID
        cmd.Parameters.Add("@ProjectTenderingNO", SqlDbType.NVarChar, 50)
        cmd.Parameters.Add("@BOQSection", SqlDbType.NVarChar, 50)
        cmd.Parameters.Add("@Part", SqlDbType.NVarChar, 200)
        cmd.Parameters.Add("@BOQITEM", SqlDbType.NVarChar, 100)
        cmd.Parameters.Add("@BOQItemNo", SqlDbType.NVarChar, 100)
        cmd.Parameters.Add("@Description", SqlDbType.NVarChar, 900)
        cmd.Parameters.Add("@Unit", SqlDbType.NChar, 10)
        cmd.Parameters.Add("@BOQTY", SqlDbType.Int)
        cmd.Parameters.Add("@ReferenceDrawing", SqlDbType.NVarChar, 100)
        cmd.Parameters.Add("@ReferenceSpecifications", SqlDbType.NVarChar, 150)
        cmd.Parameters.Add("@BOQDetailEntryID", SqlDbType.Int)

        ' Prepare command for repeated execution

        cmd.Parameters("@ProjectTenderingNO").Value = projecttnotxt.Text
        cmd.Parameters("@BOQSection").Value = txtBOQsection.Text
        cmd.Parameters("@Part").Value = txtpart.Text
        cmd.Parameters("@BOQITEM").Value = txtBOQItem.Text
        cmd.Parameters("@BOQItemNo").Value = txtBOQItemNO.Text
        cmd.Parameters("@Description").Value = txtDescription.Text
        cmd.Parameters("@Unit").Value = txtUnit.Text
        cmd.Parameters("@BOQTY").Value = sumboqty2txt.Text
        cmd.Parameters("@ReferenceDrawing").Value = txtRDrawing.Text
        cmd.Parameters("@ReferenceSpecifications").Value = txtrspe.Text
        ' cmd.Parameters("@BOQDetailEntry_ID").Value = 

        If con.State = ConnectionState.Closed Then
        End If

        cmd.Connection = con
            cmd.ExecuteNonQuery() 'Then
            MsgBox("Record Has Updated...!!", MsgBoxStyle.Information, "UPDATE EXPENDITURE")
        Catch ex As Exception
        End Try

        the error msg : Must declare the scalar variable "@ScalarName".statmenets could not be prepared 
        my scalar is the primary key and is identity how i can get its value ??? 

         ' cmd.Parameters("@BOQDetailEntry_ID").Value = 

any idea plzz
4 Years
Discussion Span
Last Post by G_Waddell

You have to add the parameter as an Output Parameter BUT an UPDATE statement will not produce one and neither would an INSERT you'd have to run a select query for it.

What kind of database are you using?

If you are using Micorsoft SQL Server then you do this with a Stored Procedure instead of querying on the fly. i.e. within the Stored Procedure run the INSERT statement then output the SCOPE_IDENTITY() to get the identity field value of the record you just created.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.