Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 11
  1. #1

    SCRIPT che non funziona

    Salve ragazzi, sto provando a mettere le mani su aspnet.
    ho preso questo script da un libro, ma non mi funziona, se qualcuno gli vuole dare un'occhiata.


    <%@ Page language="VB"%>
    <%@ import namespace="System.Data" %>
    <%@ import NameSpace="System.Data.OleDb" %>

    <script runat="server">
    'Connessione db

    dim Conn as new OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0; "&"Data Source=C:\Documents and Settings\Administrator\Desktop\dbcontroll\pippo.md b")

    sub Page_load(obj as Object, e as EventArgs)
    if not Page.IsPostBack then
    FillDataGrid()
    end if
    end sub

    sub Submit(obj as object, e as eventargs)
    'Inserimento dati
    dim i, j as integer
    dim params(7) as string
    dim strText as string
    dim blnGo as boolean=true

    j=0

    for i = 0 to AddPanel.Controls.Count - 1
    if AddPanel.controls(i).GetType Is GetType(TextBox) then
    strText = Ctype(AddPanel.Controls(i), TextBox).Text
    if strText <> "" then
    params(j)= strText
    else
    blnGo = false
    lblMessage.Text = lblMessage.Text & " RIEMPI IL CAMPO " & AddPanel.Controls(i).ID & "

    "
    lblMessage.Style("ForeColor")="#005533"
    end if
    j = j + 1
    end if
    next

    if not blnGo then
    exit sub
    end if

    dim strSQL as string = "INSERT INTO tblUsers(FirstName, LastName, Address, City, State, ZIP,Phone) VALUES ('" & params(0) & "',"&"'" & params(1) & "'," &"'" & params(2) & "',"&"'" & params(3) & "'," &"'" & params(4) & "',"&"'" & params(5) & "'," & "'" & params(6) & "')"

    ExecuteStatement(strSQL)
    FillDataGrid()
    end sub

    sub dgData_Edit(obj as object, e as DataGridCommandEventArgs)
    FillDataGrid(e.Item.ItemIndex)
    end sub

    sub dgData_Delete(obj as object, e as DataGridCommandEventArgs)
    dim strSQL as string ="DELETE FROM tblUsers "&"WHERE UserID = " & e.Item.ItemIndex + 1
    ExecuteStatement(strSQL)
    FillDataGrid()
    end sub

    sub dgData_Update(obj as object, e as DataGridCommandEventArgs)
    if UpdateDataStore(e) then
    FillDataGrid(-1)
    end if
    end sub

    sub dgData_Cancel(obj as object, e as DataGridCommandEventArgs)
    FillDataGrid(-1)
    end sub

    sub dgData_PageIndexChanged(obj as object, e as DataGridPageChangedEventArgs)
    dgData.DataBind()
    end sub

    function UpdateDataStore(e as DataGridCommandEventArgs) as boolean

    dim i,j as integer
    dim params(7) as string
    dim strText as string
    dim blnGo as boolean = true

    j=0

    for i=1 to e.Item.Cells.Count - 3
    strText = Ctype(e.Item.Cells(i).Controls(0),TextBox).Text
    if strText <> "" then
    params(j) = strText
    J = J + 1
    else
    blnGo = false
    lblMessage.text = lblMessage.Text & "errore

    "
    end if
    next

    if not blnGo then
    return false
    exit function
    end if

    dim strSQL as string =" UPDATE tblUsers SET FirstName='"& params(0) & "',"& "LastName = '" & params(1) & "',"& "Address = '" & params(2) & "'"&"City = '" & params(3) & "'"&"State = '" & params(4) & "'"&"ZIP = '" & params(5) & "'"&" = '" & params(6) & "'"& "WHERE UserID = " & Ctype(e.Item.Cells(0).Controls(1), Label).text
    ExecuteStatement(strSQL)
    return blnGo
    end function

    sub FillDataGrid(Optional EditIndex as integer =-1)
    'apre connessione
    dim objCmd as new OleDbCommand ("select * from tblUsers", Conn)
    dim objReader as OleDbDataReader

    try
    objCmd.Connection.Open()
    objReader=objCmd.ExecuteReader()
    catch ex as Exception
    lblMessage.Text = "Errore"
    end try


    dgData.DataSource = objReader
    if not EditIndex.Equals(Nothing) then
    dgData.EditItemIndex = EditIndex
    end if

    dgData.DataBind()
    objReader.Close

    objCmd.Connection.Close()

    end sub

    function ExecuteStatement(strSQL)
    dim objCmd as new OleDbCommand(strSQL, Conn)

    try
    objCmd.Connection.Open()
    objCmd.ExecuteNonQuery()
    catch ex as Exception
    lblMessage.Text="Altro Errore"
    end try
    objCmd.Connection.Close()
    end function


    </script>



    <html>
    <head>

    </head>

    <body>

    <asp:Label ID="lblMessage" runat="server"/>

    <form runat="server">
    <aspataGrid ID="dgData" runat="server"
    BorderColor="#000000"
    GridLines="Vertical"
    CellPadding="4"
    CellSpacing="0"
    Width="100%"
    AutoGenerateColumns="false"
    OnDeleteCommand="dgData_Delete"
    OnEditCommand="dgData_Edit"
    OnCancelCommand="dgData_Cancel"
    OnUpdateCommand="dgData_Update"
    OnPageIndexChanged="dgData_PageIndexChanged" >
    <columns>

    <asp:templatecolumn HeaderText="ID">
    <itemtemplate>
    <asp:Label ID="Name" runat="server" Text='<%#Container.DataItem("UserID")%>'/>
    </itemtemplate>
    </asp:templatecolumn>



    <asp:boundcolumn HeaderText="FirstName" DataField="FirstName"/>

    <asp:boundcolumn HeaderText="LastName" DataField="LastName"/>

    <asp:boundcolumn HeaderText="Address" DataField="Address"/>

    <asp:boundcolumn HeaderText="City" DataField="City"/>

    <asp:boundcolumn HeaderText="State" DataField="State"/>

    <asp:boundcolumn HeaderText="Zip" DataField="Zip"/>

    <asp:boundcolumn HeaderText="Phone" DataField="Phone"/>






    <asp:EditCommandColumn
    EditText="Edit"
    CancelText="Cancel"
    UpdateText="Update"
    HeaderText="Edit"/>

    <asp:buttoncolumn HeaderText="" Text="Delete" CommandName="delete"/>
    </columns>
    </aspataGrid>



    <asp:Panel ID="AddPanel" runat="server">
    <table>
    <tr>
    <td width="100" valign="top">
    NOME e COGNOME
    </td>
    <td width="300" valign="top">
    <asp:TextBox ID="tbFName" runat="server"/>
    <asp:TextBox ID="tbLName" runat="server"/>
    </td>
    </tr>
    <tr>
    <td valign="top">Address:</td>
    <td valign="top">
    <asp:textbox ID="tbAddress" runat="server"/>
    </td>
    </tr>

    <tr>
    <td valign="top">City, State, ZIP: </td>
    <td valign="top">
    <asp:textbox ID="tbCity" runat="server"/>,
    <asp:textbox ID="tbState" runat="server"/>
    <asp:textbox ID="tbZIP" runat="server" size="5"/>
    </td>
    </tr>
    <tr>
    <td valign="top">Phone</td>
    <td valign="top">
    <asp:textbox ID="tbPhone" runat="server"/>
    </td>
    </tr>
    <tr>
    <td colspan="2" valign="top" align="right">
    <asp:button ID="btSubmit" runat="server" Text="Add" OnClick="Submit"/>
    </td>
    </tr>
    </table>


    </aspanel>

    </p>
    </form>

    </body>
    </html>

  2. #2
    Moderatore di ASP.net L'avatar di djciko
    Registrato dal
    Nov 2002
    Messaggi
    6,887
    non mi funziona
    dovresti dire qual'e' l'errore...

  3. #3
    questa dovrebbe essere un pannello di controllo per db access.
    mi visualizza la tabella, ma qualsiasi modifica non funziona, DELETE, INSERT, UPDATE, parte l'etichetta, che sarebbe questo blocco di codice.

    function ExecuteStatement(strSQL)
    dim objCmd as new OleDbCommand(strSQL, Conn)

    try
    objCmd.Connection.Open()
    objCmd.ExecuteNonQuery()
    catch ex as Exception
    lblMessage.Text="Altro Errore"
    end try
    objCmd.Connection.Close()
    end function

  4. #4
    esiste davvero un libro dove e' pubblicato un simile malloppo di codice? se si, potresti indicarlo in modo da non far buttare via i soldi a qualcunaltro?
    per il resto fai venire fuori l'errore
    codice:
    try 
    ...
    catch ex as Exception 
    ' lblMessage.Text="Altro Errore"
    response.write(ex.message & " " & ex.stacktrace) 
    end try
    Saluti a tutti
    Riccardo

  5. #5
    Certo il libro è:"ASP.NET GUIDA COMPLETA" Apogeo
    copertina blu gialla


    allora ecco gli errori:

    DELETE=
    Impossibile eliminare dalle tabelle specificate. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at ASP.interfaccia_aspx.ExecuteStatement(Object strSQL) Altro Errore

    UPDATE:
    Errore di sintassi (operatore mancante) nell'espressione della query ''ciao come va'City = 'Roma'State = 'Italy'ZIP = '00100' = '22555555''. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at ASP.interfaccia_aspx.ExecuteStatement(Object strSQL) Altro Errore

    INSERT:
    Per l'operazione è necessaria una query aggiornabile. at System.Data.OleDb.OleDbCommand.ExecuteCommandTextE rrorHandling(Int32 hr) at System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) at System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) at System.Data.OleDb.OleDbCommand.ExecuteNonQuery() at ASP.interfaccia_aspx.ExecuteStatement(Object strSQL) Altro Errore

  6. #6
    per l'update probabilmente è un problema dato dagli apici, usa i parametri. Per l'insert è un problema di permessi in scrittura sul db
    "...non è detto che sia tardi se non guardi che ora è..."

  7. #7
    mamma mia... allora esiste. Mi sembra di averlo gia sentito in altri post altrettanto orrendi il nome di quel libro
    Come e' possibile pubblicare un qualcosa che riempie i "parametri" usando un array di stringhe
    dim params(7) as string
    quando con asp.net si utilizzano facilmente i veri parametri che possono contenere una indicazione sul tipo di dato contenuto ed evitano tanti problemi come alcuni di quelli che segnali tu.
    Come consiglio spassionato, per imparare e' meglio che lasci perdere quel brutto script. Approfondisci l'uso del command (nel tuo caso oledbcommand) e dei suoi tre principali usi: executenonquery, executereader e executescalar. Poi anche una occhiata al dataadapter non guasta (nel tuo caso oledbdataadapter). Attaccato a questi argomenti si sviluppa tutto il discorso su ado.net.
    Su msdn.microsoft.com trovi tonnellate di documentazione a riguardo.
    Saluti a tutti
    Riccardo

  8. #8
    Diciamo che come primo approccio ad aspnet mi ha detto sfiga.
    è il caro vecchio asp :rollo:
    mi consigliate un buon libro per ASP.NET 2.

  9. #9
    per asp.net 2 l'unico che conosco per sentito dire e' quelo di Dino Esposito ma gli esempi sono in c#. Io ho letto "Introducing asp.net 2" sempre di Dino Esposito e l'ho trovato molto utile.
    Saluti a tutti
    Riccardo

  10. #10

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.