Pagina 1 di 2 1 2 ultimoultimo
Visualizzazione dei risultati da 1 a 10 su 15

Discussione: Access e insert into

  1. #1

    Access e insert into

    Di seguito è riportata la funzione che dovrebbe inserire il mio record nel database

    codice:
    <%@ import Namespace="System.Security.Principal" %>
    <%@ import Namespace="System.Data.OleDb" %>
    <%@ import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb"%>
    <%@ Page Language="VB" Debug="True" validateRequest="false" %>
    <HTML>
    	<HEAD>
    		<title>Bijou - Login errato</title>
    		<script runat="server">
    		  
    		    Sub DoReg(ByVal o As Object, ByVal e As EventArgs)
    		        Dim strConn As String
    		        Dim objConn As OleDbConnection
    		        Dim strsql As String
    		        Dim objCommand As OleDbCommand
    		        
    		       
    		        strConn = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & Server.MapPath("data/bijou.mdb")
    		        objConn = New OleDbConnection(strConn)
    		        objConn.Open()
    		        
    		                
    		        strsql = "INSERT INTO Utenti ([id],[password],[role],[nome],[cognome],[indirizzo],[civico],[telefono],[cellulare],[e_mail]) VALUES ('" & txtid.Value & "','" & txtpwd.Value & "','Utente','" & txtnome.Value & "','" & txtnome.Value & "','" & txtcognome.Value & "','" & txtindirizzo.Value & "','" & txtcivico.Value & "','" & txttelefono.Value & "','" & txtcell.Value & "','" & txtmail.Value & "',);"
    		        objCommand = New OleDbCommand(strsql, objConn)
    		        objCommand.ExecuteNonQuery()
    		        'objCommand.ExecuteReader(CommandBehavior.CloseConnection)
    		        objConn.Close()
    		    End Sub
    </script>

    mentre questo è il codice del form che richiama la funzione di inserimento

    codice:
     
    
    <form  method="post" action="registrazione.aspx" runat=server>
    					<table cellSpacing="0" cellPadding="0" align="center" border="0">
    						<tr>
    							<td class="testo" id="lblid" align="left" runat="server">Nome Utente:
    							</td>
    							<td width="25"></td>
    							<td align="right"><input class="campo" id="txtid" type="text" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblpwd" align="left" runat="server">Password:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtpwd" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblnome" align="left" runat="server">Nome:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtnome" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblcognome" align="left" runat="server">Cognome:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtcognome" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblindirizzo" align="left" runat="server">Indirizzo:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtindirizzo" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblcivico" align="left" runat="server">n°civico:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtcivico" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lbltelefono" align="left" runat="server">Telefono:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txttelefono" type="text" name="Text2" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblcell" align="left" runat="server">Cellulare:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtcell" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" id="lblmail" align="left" runat="server">E-Mail:
    							</td>
    							<td width="25"></td>
    							<td align="right" width="82"><input class="campo" id="txtmail" type="text" name="Text1" runat="server" onserverchange="utente_ServerChange">
    							</td>
    						</tr>
    						<tr>
    							<td class="testo" align="left" colSpan="3">
    								<div style="margin:10,0,0,0">
    									
    
    Invia i datiCancella</P>
    								</div>
    							</td>
    						</tr>
    					</table>
    					</form>


    ho fatto tutte le prove possibile ma l'erroe che è visualizzato p il seguente

    Il numero dei valori nella query non corrisponde a quello dei campi di destinazione.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.OleDb.OleDbException: Il numero dei valori nella query non corrisponde a quello dei campi di destinazione.

    Source Error:


    Line 23: strsql = "INSERT INTO [Utenti] ([id],[password],[role],[nome],[cognome],[indirizzo],[civico],[telefono],[cellulare],[e_mail]) VALUES ('" & txtid.Value & "','" & txtpwd.Value & "','Utente','" & txtnome.Value & "','" & txtnome.Value & "','" & txtcognome.Value & "','" & txtindirizzo.Value & "','" & txtcivico.Value & "','" & txttelefono.Value & "','" & txtcell.Value & "','" & txtmail.Value & "',);"
    Line 24: objCommand = New OleDbCommand(strsql, objConn)
    Line 25: objCommand.ExecuteNonQuery()
    Line 26: 'objCommand.ExecuteReader(CommandBehavior.CloseCon nection)
    Line 27: objConn.Close()


    Source File: C:\Inetpub\wwwroot\bijouremake\registrazione.aspx Line: 25

    Stack Trace:


    [OleDbException (0x80040e14): Il numero dei valori nella query non corrisponde a quello dei campi di destinazione.]
    System.Data.OleDb.OleDbCommand.ExecuteCommandTextF orSingleResult(tagDBPARAMS dbParams, Object& executeResult) +177
    System.Data.OleDb.OleDbCommand.ExecuteCommandText( Object& executeResult) +194
    System.Data.OleDb.OleDbCommand.ExecuteCommand(Comm andBehavior behavior, Object& executeResult) +56
    System.Data.OleDb.OleDbCommand.ExecuteReaderIntern al(CommandBehavior behavior, String method) +105
    System.Data.OleDb.OleDbCommand.ExecuteNonQuery() +89
    ASP.registrazione_aspx.DoReg(Object o, EventArgs e) in C:\Inetpub\wwwroot\bijouremake\registrazione.aspx: 25
    System.Web.UI.HtmlControls.HtmlAnchor.OnServerClic k(EventArgs e) +75
    System.Web.UI.HtmlControls.HtmlAnchor.RaisePostBac kEvent(String eventArgument) +96
    System.Web.UI.HtmlControls.HtmlAnchor.System.Web.U I.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +172
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4924



    ho provato a togliere le quadrema mi dice che sbaglio la insert into


    ma dove???? :master:

  2. #2
    nella query hai dichiarato 10 campi ma ne valorizzi 11, hai messo due volte txtnome.Value
    "...non è detto che sia tardi se non guardi che ora è..."

  3. #3
    Utente di HTML.it L'avatar di cassano
    Registrato dal
    Aug 2004
    Messaggi
    3,002
    ti consiglio di usare i parametri o store procedure cosi almeno hai tutto più ordinato e capisci subito il problema.

  4. #4
    si l'ho fatto cn i parametri.... ma tutto funziona bene in locale e quando pubblico l'intero sito non aggiunge alcun record al database!

  5. #5
    Utente di HTML.it L'avatar di Sonikag
    Registrato dal
    Mar 2004
    Messaggi
    2,080
    Hai lo stesso framework?

  6. #6

  7. #7
    addirittura mi dice che c'è bisogno di una query aggiornabile! on line????

  8. #8
    posto il code magari ci si capisce qlkosa....

    codice:
    <%@ Page Language="VB" %>
    <%@ Import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.OleDb" %>
    <script runat="server">
    	
        Sub DoReg(ByVal o As Object, ByVal e As EventArgs)
            Dim str As String
            Dim cn As OleDbConnection
            Dim sql As String
            Dim cmd As OleDbCommand
            
            str = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + Server.MapPath("data/bijou.mdb")
            cn = New OleDbConnection(str)
            cn.Open()
            
            sql = "INSERT INTO Utenti ([id],[password],role,nome,cognome,indirizzo,civico,telefono,cellulare,e_mail) VALUES (?,?,?,?,?,?,?,?,?,?)"
            cmd = New OleDbCommand(sql, cn)
            cmd.Parameters.Add("@id", nickname.Text)
            cmd.Parameters.Add("@password", pass.Text)
            cmd.Parameters.Add("@role", "Utente")
            cmd.Parameters.Add("@nome", nome.Text)
            cmd.Parameters.Add("@cognome", cognome.Text)
            cmd.Parameters.Add("@indirizzo", indirizzo.Text)
            cmd.Parameters.Add("@civico", civico.Text)
            cmd.Parameters.Add("@telefono", telefono.Text)
            cmd.Parameters.Add("@cellulare", cellulare.Text)
            cmd.Parameters.Add("@e_mail", e_mail.Text)
            cmd.ExecuteReader()
    
            cn.Close()
        
            
            Response.Redirect("default.aspx")
            ' }
            ' }
        End Sub
        
       
    </script>
    <html>
        <head>
            <title>Firma il Guestbook in Asp.NET</title>
        </head>
    <body>
    
    <h2>Firma il Guestbook in Asp.NET</h2>
    
    <form id="Modulo" name="Modulo" method="post" action="registrazione.aspx" runat="server">
    	Nickname
    
    	<asp:Textbox id="nickname" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="pass" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="nome" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="cognome" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="indirizzo" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="civico" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="telefono" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="cellulare" runat="server" />
    
    	Messaggio
    
    	<asp:Textbox id="e_mail" runat="server" />
    
    	Messaggio
    
    
    
    	<a href=#  onserverClick="DoReg" id="Send" runat="server" >invia
    	</a>
    	
    
    
    	<asp:label id="Errore" ForeColor="#FF0000" runat="server" />
    </form>
    </body>
    </html>

    proprio non capisco!!!!

  9. #9
    forse e dico forse...il problema è un "informazioni di blocco record di microsoft access"

    se riesco a togliere qule blocco funziona tutto il problema è capire come si crea!!!!(ammesso e concesso che sia qs ilproblema)

  10. #10
    oddio...allora cn IIS non funziona nulla, ma se iso il visual web developer 2005 funziona tutto! se pubblico non funziona
    io sto impazzendo perchè è evidente che la query funziona ma c'è qlke impostazione birichina che nn va...eppure ho dato tutti i permessi possibili!

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.