Hi all the Experts,
I’m quiet to new to working Binary data in aps.net. I have been trying now for the last 6 days but cannot get the following from working. I have attached the UI, the Deafult.aspx html coding and the code behind Default.aspx.cs.
I seem to have the following error when I try to insert data into the database. Can anyone help me please? Your assistance would be greatly appreciated.
Thank you in advance for any help or comments
Server Error in '/' Application.
Incorrect syntax near '@Upload'.
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 '@Upload'. Source Error:
Line 67: {
Line 68: con.Open();
Line 69: cmm.ExecuteNonQuery();
Line 70: con.Close();
Line 71:
Source File: c:\users\able valued client\documents\visual studio 2010\Projects\UploadFileDropdownlist2015\UploadFileDropdownlist2015\Default.aspx.cs Line: 69 Stack Trace:
[SqlException (0x80131904): Incorrect syntax near '@Upload'.]
System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +1767866
System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection, Action`1 wrapCloseInAction) +5352418
System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj, Boolean callerHasConnectionLock, Boolean asyncClose) +244
System.Data.SqlClient.TdsParser.TryRun(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj, Boolean& dataReady) +1691
System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString) +269
System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async, Int32 timeout, Task& task, Boolean asyncWrite, SqlDataReader ds) +1406
System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, TaskCompletionSource`1 completion, Int32 timeout, Task& task, Boolean asyncWrite) +177
System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(TaskCompletionSource`1 completion, String methodName, Boolean sendToPipe, Int32 timeout, Boolean asyncWrite) +205
System.Data.SqlClient.SqlCommand.ExecuteNonQuery() +160
UploadFileDropdownlist2015.Default.btnSubmit_Click(Object sender, EventArgs e) in c:\users\able valued client\documents\visual studio 2010\Projects\UploadFileDropdownlist2015\UploadFileDropdownlist2015\Default.aspx.cs:69
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +9633194
System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +103
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +10
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +13
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +35
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1724
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
Defult.aspx
<asp:Label ID="Label1" runat="server" Text="Resume Title:"></asp:Label>
</td>
<td>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</tr>
<tr>
<td class="style2">
<asp:Label ID="Label2" runat="server" Text="Brief Description:"></asp:Label>
<asp:TextBox ID="TextBox2" runat="server" TextMode="MultiLine"></asp:TextBox>
<asp:Label ID="Label3" runat="server" Text="Email:"></asp:Label>
<asp:TextBox ID="TextBox3" runat="server"></asp:TextBox>
<asp:Label ID="Label4" runat="server" Text="Address 1:"></asp:Label>
<asp:TextBox ID="TextBox4" runat="server"></asp:TextBox>
<asp:Label ID="Label5" runat="server" Text="Address 2:"></asp:Label>
<asp:TextBox ID="TextBox5" runat="server"></asp:TextBox>
<asp:Label ID="Label6" runat="server" Text="City:"></asp:Label>
<asp:TextBox ID="TextBox6" runat="server"></asp:TextBox>
<asp:Label ID="Label7" runat="server" Text="State:"></asp:Label>
<asp:TextBox ID="TextBox7" runat="server"></asp:TextBox>
<asp:Label ID="Label8" runat="server" Text="Location:"></asp:Label>
<asp:TextBox ID="TextBox8" runat="server"></asp:TextBox>
<asp:Label ID="Label9" runat="server" Text="Country:"></asp:Label>
<asp:DropDownList ID="DropDownList1" runat="server" AutoPostBack="True">
<asp:ListItem>PNG</asp:ListItem>
<asp:ListItem>Fiji</asp:ListItem>
<asp:ListItem>Philippines</asp:ListItem>
</asp:DropDownList>
<asp:Label ID="Label10" runat="server" Text="ZipCode:"></asp:Label>
<asp:TextBox ID="TextBox10" runat="server"></asp:TextBox>
<asp:Label ID="Label11" runat="server" Text="Total Experience:"></asp:Label>
<asp:TextBox ID="TextBox11" runat="server"></asp:TextBox>
<asp:Label ID="Label12" runat="server" Text="Upload:"></asp:Label>
<asp:FileUpload ID="FileUpload1" runat="server" />
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit"
onclick="btnSubmit_Click" />
</table>
Code Behind Defult.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
namespace UploadFileDropdownlist2015
{
public partial class Default : System.Web.UI.Page
SqlCommand cmm;
SqlConnection con;
SqlDataAdapter da;
String s;
protected void Page_Load(object sender, EventArgs e)
cmm = new SqlCommand("Insert Into tblResumeDetails Values(@ResumeTitle, @ResumeDescription, @Email, @Address1, @Address2, @City, @State, @Location, @Country, @ZipCode,@TotalExperience,@Upload",con);
con = new SqlConnection(ConfigurationManager.ConnectionStrings["FileUploadDropdownlist2015DBConnectionString"].ToString());
cmm.Connection=con;
da = new SqlDataAdapter(cmm);
if (FileUpload1.HasFile)
string fileExt = System.IO.Path.GetExtension(FileUpload1.FileName);
if (fileExt==".pdf")
s=MapPath("img");
s = s + "/" + FileUpload1.FileName;
FileUpload1.SaveAs(s);
}
else
Response.Write("Invalid Upload File Format");
cmm.Parameters.AddWithValue("@ResumeTitle", TextBox1.Text);
cmm.Parameters.AddWithValue("@ResumeDescription", TextBox2.Text);
cmm.Parameters.AddWithValue("@Email", TextBox3.Text);
cmm.Parameters.AddWithValue("@Address1", TextBox4.Text);
cmm.Parameters.AddWithValue("@Address2", TextBox5.Text);
cmm.Parameters.AddWithValue("@City", TextBox6.Text);
cmm.Parameters.AddWithValue("@State", TextBox7.Text);
cmm.Parameters.AddWithValue("@Location", TextBox8.Text);
cmm.Parameters.AddWithValue("@Country", DropDownList1.SelectedValue);
cmm.Parameters.AddWithValue("@ZipCode", TextBox10.Text);
cmm.Parameters.AddWithValue("@TotalExperience", TextBox11.Text);
cmm.Parameters.AddWithValue("@Upload", s);
protected void btnSubmit_Click(object sender, EventArgs e)
con.Open();
cmm.ExecuteNonQuery();
con.Close();
mework Version:4.0.30319; ASP.NET Version:4.0.30319.34237