Visualizzazione dei risultati da 1 a 2 su 2

Discussione: strored procedure

  1. #1

    strored procedure

    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

  2. #2
    Utente di HTML.it
    Registrato dal
    Aug 2001
    Messaggi
    1,482
    codice:
     
    dim objparam as oledbparameter
    
    objparam = UpdateCommand.Parameter.add("@au_id",oledbType.integer) 
    objparam.value=id 
    objparam.direction=ParameterDirection.Input 
    
    objparam = UpdateCommand.Parameter.add("@au_lname",oledbType.char)
    objparam.value=lname 
    objparam.direction=ParameterDirection.Input
    
    'continua tu....
    Spero funzioni. Crede che l'errore fosse anche nel fatto che dichiaravi new ogni volta l'oggetto oledbparameter.

    Hey hey, my my Rock and roll can never die!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.