error in declaring the scalar variable
Hi,
Hi,
I am trying to update a row in the edit mode in a grid view . I am posting the method used below.
Please look in to the error and the method mentioned below and fix the error.
Error message: - Must declare the scalar variable "@description".
It immediately goes to catch after executing the Execute NonQuery( ) method.
Protected Sub AlarmGrid_RowUpdating(ByVal sender As Object, ByVal e As GridViewUpdateEventArgs)
'Dim AlarmID As Integer = Int.Parse(AlarmGrid.Rows(e.RowIndex).Cells(0)).Tex t
Dim description As String = (AlarmGrid.Rows(e.RowIndex).Cells(2)).Text
'Dim mode As String = (AlarmGrid.Rows(e.RowIndex).Cells(3)).Text
Dim active As String = (AlarmGrid.Rows(e.RowIndex).Cells(4)).Text
Dim regulatory_alarm As String = (AlarmGrid.Rows(e.RowIndex).Cells(5)).Text
Dim auto_acknowledge As String = (AlarmGrid.Rows(e.RowIndex).Cells(5)).Text
Dim rowsAffected As Integer
Dim AlarmConn As SqlConnection
AlarmConn = New SqlConnection(ConfigurationManager.ConnectionStrin gs("CMSConnStr").ConnectionString)
Dim QueryString As String = String.Empty
Dim PlantCommand As SqlCommand = New SqlCommand()
Try
AlarmConn.Open()
QueryString = "Update AlarmDefinition " & _
" set description = @description,mode = @mode, active = @active , regulatory_alarm = @regulatoryalarm , " & _
"auto_acknowledge = @autoacknowledge where(Alarm_id = " & Me.AlarmId & " and Unit_id = " & Me.UnitId & " )"
PlantCommand = New SqlCommand(QueryString, AlarmConn)
PlantCommand.Parameters.Add("@decription", SqlDbType.VarChar, 100).Value = description
'PlantCommand.Parameters.Add("@mode", SqlDbType.Int, 1).Value = mode
PlantCommand.Parameters.Add("@active", SqlDbType.Char, 1).Value = active
PlantCommand.Parameters.Add("@regulatory_alarm", SqlDbType.Char, 1).Value = regulatory_alarm
PlantCommand.Parameters.Add("@auto_acknowledge", SqlDbType.Char, 1).Value = auto_acknowledge
rowsAffected = PlantCommand.ExecuteNonQuery()
'End If
Catch ex As Exception
Me.AlarmErrorMsg = ex.Message
Dim errorMsg As String = ex.Message & " :Exception Inside AlarmModification.AlarmGrid_RowUpdating( )"
'Check if an exception occured while logging to the database
'Initially store the errorMsg in the CLogger property
CLogger.LogDB = "N"
CLogger.CustomErrorMsg = errorMsg
If CLogger.WriteLogMsg(errorMsg, "E") Then
CLogger.LogDB = "Y"
End If
Throw New Exception(errorMsg)
End Try
'EditAlarmRecord(UnitId, active, description, RegulatoryAlarm, AutoAcknowledge)
AlarmGrid.EditIndex = -1
AlarmGrid.DataSource = AlarmModification
AlarmGrid.DataBind()
FilterDataBind()
End Sub
Thanks,
Sreekanth Nagabandi
|