Click here to Skip to main content
Rate this: bad
good
Please Sign up or sign in to vote.
See more: C# ASP.NET ADO.NET
System.Data.SqlClient.SqlException was unhandled by user code
  Message="Incorrect syntax near ')'."
  Source=".Net SqlClient Data Provider"
  ErrorCode=-2146232060
  Class=15
  LineNumber=1
  Number=102
  Procedure=""
  Server="\\\\.\\pipe\\3A2A659F-F9B2-41\\tsql\\query"
  State=1
  StackTrace:
       at System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection)
       at System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj)
       at System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj)
       at System.Data.SqlClient.SqlCommand.FinishExecuteReader(SqlDataReader ds, RunBehavior runBehavior, String resetOptionsString)
       at System.Data.SqlClient.SqlCommand.RunExecuteReaderTds(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, Boolean async)
       at System.Data.SqlClient.SqlCommand.RunExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream, String method, DbAsyncResult result)
       at System.Data.SqlClient.SqlCommand.InternalExecuteNonQuery(DbAsyncResult result, String methodName, Boolean sendToPipe)
       at System.Data.SqlClient.SqlCommand.ExecuteNonQuery()
       at _Default.Button1_Click(Object sender, EventArgs e) in c:\Documents and Settings\kachu\My Documents\Visual Studio 2008\WebSites\newimginsert\Default.aspx.cs:line 44
       at System.Web.UI.WebControls.Button.OnClick(EventArgs e)
       at System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument)
       at System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData)
       at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)
  InnerException: 
this is my code
using System;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.Sql;
using System.Data.SqlClient;
 
public partial class _Default : System.Web.UI.Page 
{
   //   SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDBFileName=|DataDirectory|\\ImageDB.mdf; integrated security=true;user instance=true;");
    SqlConnection con = new SqlConnection("Data Source=.\\SQLEXPRESS;AttachDBFileName=|DataDirectory|\\ImageDB.mdf; integrated security=true;user instance=true;");
 
    protected void Page_Load(object sender, EventArgs e)
    {
 
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        if (FileUpload1.HasFile)
        {
            //byte[] img = new byte[FileUpload1, postedfile.contentLength];
            byte[] img = new byte[FileUpload1.PostedFile.ContentLength];
            HttpPostedFile myimg = FileUpload1.PostedFile;
            myimg.InputStream.Read(img, 0, FileUpload1.PostedFile.ContentLength);
            SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename,)", con);
            
            SqlParameter imgname = new SqlParameter("@imagename", SqlDbType.VarChar,25);
            imgname.Value = TextBox1.Text;
            cmd.Parameters.Add(imgname);
            
            SqlParameter uploading = new SqlParameter("@image", SqlDbType.Image);
            uploading.Value = img;
            cmd.Parameters.Add(uploading);
            
            con.Open();
            
            cmd.ExecuteNonQuery();
            
            con.Close();
            
            Label1.Text = "image uploaded........";
 

        }
        else
            Label1.Text = "can't upload file.........";
    }
}
n i am following video
http://www.youtube.com/watch?v=HYdsHttQzDw
 

plz help me thanks in advance and my prob is i want to insert and retrieve image from sql and to retrieve image to gridview i am not getting correct code so working on it from past 4 days but still not able to do..Frown | :-(
 

[edit]Code blocks added - OriginalGriff[/edit]
Posted 5-Apr-12 21:07pm
Edited 5-Apr-12 21:14pm
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 2

Your query is incorrect. Try to copy the query from here and run it in SQL Server Management Studio. It will give you an idea on what syntax is incorrect.
  Permalink  
Comments
Monjurul Habib at 6-Apr-12 5:13am
   
5!
Abhinav S at 6-Apr-12 6:29am
   
Thank you Monjurul.
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Take out the comma.
SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename,)", con);
Becomes
SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename)", con);
 

[edit]
You might actually want to add the other parameter instead:
SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename,@image)", con);
[/edit]
  Permalink  
v2
Comments
karthikh87 at 6-Apr-12 3:31am
   
i had forgot to write "@image" after comma sir.. and thanks for the great support
SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename,@image)", con);
 
and i wish and request for the same support al the time and its great to be in this forum
thanks once again and if possible can u please give the code to display image in grid view as i am not getting from many days m sorry if i am expecting more m very new to this development sir..
OriginalGriff at 6-Apr-12 3:35am
   
You're welcome!
Have a look at this article - it does just that.
http://www.codeproject.com/Articles/268123/Display-Store-and-Retrieve-Image-Data-from-Databas
Monjurul Habib at 6-Apr-12 5:13am
   
5!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 3

Dear friend,
 
Please check this line
SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename,)", con);
 
Please remove bold semicolon
 
may be your problem will solve.
 

best regards,
Anil Avhad
  Permalink  
v2
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 4

Incorrect query.
check the syntax and run it in SQL..
 
you are just passing only one value ..plz check it
 
   SqlCommand cmd = new SqlCommand("insert into myimage(ImageName,Image) values(@imagename,)", con);
  Permalink  
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
0 Sergey Alexandrovich Kryukov 6,676
1 OriginalGriff 6,056
2 CPallini 2,473
3 Richard MacCutchan 1,697
4 Abhinav S 1,560


Advertise | Privacy | Mobile
Web04 | 2.8.140821.2 | Last Updated 16 Apr 2012
Copyright © CodeProject, 1999-2014
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100