Visualizzazione dei risultati da 1 a 3 su 3
  1. #1
    Utente di HTML.it
    Registrato dal
    Nov 2005
    Messaggi
    6

    insert PDF file - repository

    Salve boys
    devo costruire il classico FORM DI INSERIMENTO in una database SQL per REPOSITORY di documenti..
    quindi è previsto oltre l'inserimento in semplici campi...l'inserimento di documenti PDF ..
    ma mi da errore..SUGGERIMENTI?ecco il codice :


    uso VWD 2005 ed SQL express 2005


    <%@ Page Language="c#" %>
    <%@ import Namespace="System" %>
    <%@ import Namespace="System.IO" %>
    <%@ import Namespace="System.Data" %>
    <%@ Import Namespace="System.Data.SqlClient"%>


    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

    <script runat="server">

    void BtnUp_Click(Object s, EventArgs e) {
    int dimensione=inputFile.PostedFile.ContentLength;

    if (dimensione>0) {
    string db, strsql;
    Byte[] FileByteArray= new Byte[dimensione];
    Stream StreamObject=inputFile.PostedFile.InputStream;
    StreamObject.Read(FileByteArray, 0, dimensione);
    db="database.mdf";
    SqlConnection myconnection=new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDbFilename=C:\\Inetpub\ \wwwroot\\tesi\\App_Data\\database.mdf;Integrated Security=True;Connect Timeout=30;User Instance=True") ;
    strsql = "insert into upload(Nome, Cognome, Dipartmento, Titolo, Data, Tipo, keywords, Abstract, ISBN, documento, nome, size, contenttype) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    SqlCommand mycommand = new SqlCommand(strsql, myconnection);
    mycommand.Parameters.Add("@Nome", SqlType.VarChar, 50).Value=Nome.Text;
    mycommand.Parameters.Add("@Cognome", SqlType.VarChar, 50).Value = Cognome.Text;
    mycommand.Parameters.Add("@Dipartimento ", SqlType.VarChar, 50).Value = Dipartimento.Text;
    mycommand.Parameters.Add("@Titolo", SqlType.VarChar, 50).Value = Titolo.Text;
    mycommand.Parameters.Add("@Data", SqlType.VarChar, 50).Value = Data.Text;
    mycommand.Parameters.Add("@Tipo", SqlType.VarChar, 50).Value = Tipo.Text;
    mycommand.Parameters.Add("@Keywords", SqlType.VarChar, 50).Value = Keywords.Text;
    mycommand.Parameters.Add("@Abstract", SqlType.VarChar, 50).Value = Abstract.Text;
    mycommand.Parameters.Add("@ISBN", SqlType.VarChar, 50).Value = ISBN.Text;

    mycommand.Parameters.Add("@immagine", SqlType.Binary, dimensione).Value=FileByteArray;
    mycommand.Parameters.Add("@descrizione", SqlType.VarChar, 50).Value=Path.GetFileName(inputFile.PostedFile.Fi leName);
    mycommand.Parameters.Add("@size", SqlType.Integer, 50).Value=dimensione;
    mycommand.Parameters.Add("@contenttype", SqlType.VarChar, 50).Value=inputFile.PostedFile.ContentType;
    myconnection.Open();
    mycommand.ExecuteNonQuery();
    myconnection.Close();
    messaggio.Text="OK!";
    }
    else
    {
    messaggio.Text="Nessun file selezionato!";
    }
    }
    </script>

    <html xmlns="http://www.w3.org/1999/xhtml" >
    <head id="Head1" runat="server">
    <title>INSERIMENTO</title>
    <LINK href="mauro.css" rel=stylesheet>


    </head>

    <body bgcolor="#DFE5F2" style="font-size: 12pt">
    <form id="Form1" enctype="multipart/form-data" runat="server">
    INSERICI DOCUMENTO

    <div id="Results" align="center" runat="server" />

    <p align="left">
    Seleziona il documento sul tuo HD quindi clicca su upload:

    <input id="inputFile" type="file" size="40" runat="server" />

    Nome: <asp:TextBox id="Nome" runat="server" Width="259px"></asp:TextBox>



    Cognome: <asp:TextBox id="Cognome" runat="server" Width="259px"></asp:TextBox>



    Dipartimento:<asp:TextBox id="Dipartimento" runat="server" Width="259px"></asp:TextBox>



    Titolo: <asp:TextBox id="Titolo" runat="server" Width="259px"></asp:TextBox>



    Data: <asp:TextBox id="Data" runat="server" Width="259px"></asp:TextBox>



    Tipo: <asp:TextBox id="Tipo" runat="server" Width="259px"></asp:TextBox>



    Keywords : <asp:TextBox id="Keywords" runat="server" Width="259px"></asp:TextBox>




    Abstract : <asp:TextBox id="Abstract" runat="server" Width="259px"></asp:TextBox>



    ISBN : <asp:TextBox id="ISBN" runat="server" Width="259px"></asp:TextBox>



    <asp:label id="messaggio" runat="server" Font-Bold="True"></asp:label>
    </p>

    <input id="BtnUp" value="Upload!" runat="server" onserverclick="BtnUp_Click" />
    </form>
    </body>
    </html>



    mi da però questo errore:

    Server Error in '/tesi' Application.
    --------------------------------------------------------------------------------

    Compilation Error
    Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

    Compiler Error Message: CS0103: The name 'SqlType' does not exist in the current context

    Source Error:



    Line 22: strsql = "insert into upload(Nome, Cognome, Dipartmento, Titolo, Data, Tipo, keywords, Abstract, ISBN, documento, nome, size, contenttype) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
    Line 23: SqlCommand mycommand = new SqlCommand(strsql, myconnection);
    Line 24: mycommand.Parameters.Add("@Nome", SqlType.VarChar, 50).Value=Nome.Text;
    Line 25: mycommand.Parameters.Add("@Cognome", SqlType.VarChar, 50).Value = Cognome.Text;
    Line 26: mycommand.Parameters.Add("@Dipartimento ", SqlType.VarChar, 50).Value = Dipartimento.Text;


    Source File: c:\Inetpub\wwwroot\tesi\uploadIMAGE.aspx Line: 24


    SUGGERIMENTI?grazie cmq!
    conoscete qualche buon script di inserimento PDF file in un database?

  2. #2
    Devi proprio salvare i PDF all'interno del db?
    Perchè non salvi il PDF come file fisico e nel db salvi solo il link o il path sul server?
    In questo modo il db non diventa gigante come dimensione.

    Comunque a memoria mi sembra sia SqlDbType e non SqlType.

    Fammi sapere
    Ciao
    K
    Kalman

  3. #3
    Utente di HTML.it
    Registrato dal
    Nov 2005
    Messaggi
    6
    grazie gentilissimo era come dicevi!
    ora il debug funge ma quando vado ad inserire mi dà il solito errore

    Incorrect syntax near '?'.
    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.SqlClient.SqlException: Incorrect syntax near '?'.

    Source Error:


    Line 39: mycommand.Parameters.Add("@contenttype", SqlDbType.VarChar, 50).Value = inputFile.PostedFile.ContentType;
    Line 40: myconnection.Open();
    Line 41: mycommand.ExecuteNonQuery();
    Line 42: myconnection.Close();
    Line 43: messaggio.Text="OK!";


    Source File: c:\Inetpub\wwwroot\tesi\uploadIMAGE.aspx Line: 41

    Stack Trace:


    [SqlException (0x80131904): Incorrect syntax near '?'.]
    System.Data.SqlClient.SqlConnection.OnError(SqlExc eption exception, Boolean breakConnection) +177
    System.Data.SqlClient.SqlInternalConnection.OnErro r(SqlException exception, Boolean breakConnection) +68
    System.Data.SqlClient.TdsParser.ThrowExceptionAndW arning(TdsParserStateObject stateObj) +199
    System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2305
    System.Data.SqlClient.SqlCommand.FinishExecuteRead er(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +147
    System.Data.SqlClient.SqlCommand.RunExecuteReaderT ds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async) +1021
    System.Data.SqlClient.SqlCommand.RunExecuteReader( CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result) +314
    System.Data.SqlClient.SqlCommand.InternalExecuteNo nQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +413
    System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +115
    ASP.uploadimage_aspx.BtnUp_Click(Object s, EventArgs e) in c:\Inetpub\wwwroot\tesi\uploadIMAGE.aspx:41
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
    System.Web.UI.WebControls.Button.RaisePostBackEven t(String eventArgument) +97
    System.Web.UI.WebControls.Button.System.Web.UI.IPo stBackEventHandler.RaisePostBackEvent(String eventArgument) +7
    System.Web.UI.Page.RaisePostBackEvent(IPostBackEve ntHandler sourceControl, String eventArgument) +11
    System.Web.UI.Page.RaisePostBackEvent(NameValueCol lection postData) +33
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921


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.