Ho un problema con una stored procedure il cui SQL è questo:
UpdateCommand.CommandText ="UPDATE autore SET cognome = @au_lname, nome = @au_fname WHERE idautore = @au_id
Ecco il codice: (premesso che se costruisco a mano l'SQL cioè con una concatenazione di stringhe il tutto va)
Sub DataGrid_Update(Sender As Object, E As DataGridCommandEventArgs)
' update the database with the new values
dim id as string= Ctype(e.Item.FindControl("idautore"), TextBox).Text
Dim lname As String = CType(e.Item.Cells(3).Controls(0), TextBox).Text
Dim fname As String = CType(e.Item.Cells(4).Controls(0), TextBox).Text
dim cat as string
' TODO: update the Command value for your application
Dim myConnection As New OleDbConnection(ConnectionString)
cat="queryparam"
Dim UpdateCommand As OleDbCommand = new OledbCommand(cat,myConnection)
updatecommand.commandtype=commandtype.storedproced ure
dim objparam as new oledbparameter("@au_id",oledbType.integer)
objparam.value=id
UpdateCommand.parameters.add(objparam)
objparam = new oledbparameter("@au_lname",oledbType.char)
objparam.value=lname
UpdateCommand.parameters.add(objparam)
objparam = new oledbparameter("@au_fname",oledbType.char)
objparam.value=fname
UpdateCommand.parameters.add(objparam)
' execute the command
Try
myConnection.Open()
UpdateCommand.ExecuteNonQuery()
Catch ex as Exception
Message.Text = ex.ToString()
Finally
myConnection.Close()
End Try
' Resort the grid for new records
If AddingNew = True Then
DataGrid1.CurrentPageIndex = 0
AddingNew = false
End If
' rebind the grid
DataGrid1.EditItemIndex = -1
BindGrid()
End Sub
Non intercetta alcun errre nella clausola try ... catch BO!
Grazie