Salve è la prima volta che scrivo..
sto implementando il classico form di inderimento dati in una tabella dove l utente può scrivere dati e pdf nel database ecco una parte dello script in c#:
strsql = "insert into upload(Nome, Cognome, Dipartmento, Titolo, Data, Tipo, keywords, Abstract, ISBN, ISNN, documento, descrizione, size, contenttype) values(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";
SqlCommand mycommand = new SqlCommand(strsql, myconnection);
mycommand.Parameters.Add("@Nome", SqlDbType.VarChar, 50).Value = Nome.Text;
mycommand.Parameters.Add("@Cognome", SqlDbType.VarChar, 50).Value = Cognome.Text;
mycommand.Parameters.Add("@Dipartimento ", SqlDbType.VarChar, 50).Value = Dipartimento.Text;
mycommand.Parameters.Add("@Titolo", SqlDbType.VarChar, 50).Value = Titolo.Text;
mycommand.Parameters.Add("@Data", SqlDbType.VarChar, 50).Value = Data.Text;
mycommand.Parameters.Add("@Tipo", SqlDbType.VarChar, 50).Value = Tipo.Text;
mycommand.Parameters.Add("@Keywords", SqlDbType.VarChar, 50).Value = Keywords.Text;
mycommand.Parameters.Add("@Abstract", SqlDbType.VarChar, 50).Value = Abstract.Text;
mycommand.Parameters.Add("@ISBN", SqlDbType.VarChar, 50).Value = ISBN.Text;
mycommand.Parameters.Add("@ISNN", SqlDbType.VarChar, 50).Value = ISBN.Text;
mycommand.Parameters.Add("@documento", SqlDbType.Binary, dimensione).Value = FileByteArray;
mycommand.Parameters.Add("@descrizione", SqlDbType.VarChar, 50).Value = Path.GetFileName(inputFile.PostedFile.FileName);
//mycommand.Parameters.Add("@size", SqlDbType.Integer, 50).Value = dimensione;
mycommand.Parameters.Add("@contenttype", SqlDbType.VarChar, 50).Value = inputFile.PostedFile.ContentType;
myconnection.Open();
mycommand.ExecuteNonQuery();
myconnection.Close();
messaggio.Text="OK!";
}
else
{
messaggio.Text="Nessun file selezionato!";
}
}
ma mi da il seguente errore ... che significa?
grazie
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 40: mycommand.Parameters.Add("@contenttype", SqlDbType.VarChar, 50).Value = inputFile.PostedFile.ContentType;
Line 41: myconnection.Open();
Line 42: mycommand.ExecuteNonQuery();
Line 43: myconnection.Close();
Line 44: messaggio.Text="OK!";
Source File: c:\Inetpub\wwwroot\tesi\inserimentoPDF.aspx Line: 42
Stack Trace:
[SqlException (0x80131904): Incorrect syntax near '?'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +177
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +68
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +199
System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2305
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +147
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(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.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe) +413
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +115
ASP.inserimentopdf_aspx.BtnUp_Click(Object s, EventArgs e) in c:\Inetpub\wwwroot\tesi\inserimentoPDF.aspx:42
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +75
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +97
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +7
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +11
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +4921