INSERT FORM + PDF

venerdì 13 aprile 2007 - 17.15

3rdEyeD Profilo | Newbie

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.FileName);
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">
<strong>INSERICI DOCUMENTO</strong>

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

<p align="left">
Seleziona il documento sul tuo HD quindi clicca su upload:<br />
<input id="inputFile" type="file" size="40" runat="server" /><br />
Nome: <asp:TextBox id="Nome" runat="server" Width="259px"></asp:TextBox>
<br />

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

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

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

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

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

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


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

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

<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!
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5