Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Error 170:In correct Syntax- SQL Server and C#

Error 170:In correct Syntax- SQL Server and C#

Scheduled Pinned Locked Moved C#
databasehelpcsharpsql-serversysadmin
3 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    SilimSayo
    wrote on last edited by
    #1

    I am trying to call a stored procedure from C#. The stored procedure, called create_journal, compiles succesfully on SQL Server and also runs sucessfully when executed in query analyzeer. It takes a datetime input parameter. When I call it from C#, I get an SqlException which says Error 170. Line 1 Incorrect syntax near create_journal_entry The stored Procedure begins as follows

    ALTER PROCEDURE create_journal_entry
    @eom_date DATETIME --End of month date
    AS

    DECLARE

    @next_jrnl_num VARCHAR(20)

    The c# code is

    private void createJEs()
    {
    DateTime cutOffDate;
    cutOffDate=this.dtpCutOffDate.Value;

    SqlConnection conn =new SqlConnection(DBConnection.connectionString());
    conn.Open();
    SqlCommand comm=new SqlCommand("create\_journal\_entry",conn);
        comm.Parameters.Add("@eom\_date",SqlDbtype.DateTime);
        comm.parameters\[“@eom\_date”\].value=this.dtpCutOffDate.Value;
    
        try
    {
    	comm.ExecuteNonQuery();	
    	moveFiles();
                MessageBox.Show("Data has been successfully sent to the   
                GL.", "Success",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
    }
    catch(SqlException ex)
    {
            MessageBox.Show("Error "+ex.Number + " "+ ex.Message,"SqlServer 
            error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
    }
    catch(Exception ex)
    {
            MessageBox.Show(ex.Message,"System Error",  
            MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
    }
    finally
    {
    	if (conn!=null)
    	{
    		conn.Close();
    	}
    }
    

    }

    NB this.dtpCutOffDate is a DateTime picker control. Please help as I am going nuts over this. Thanks

    I 1 Reply Last reply
    0
    • S SilimSayo

      I am trying to call a stored procedure from C#. The stored procedure, called create_journal, compiles succesfully on SQL Server and also runs sucessfully when executed in query analyzeer. It takes a datetime input parameter. When I call it from C#, I get an SqlException which says Error 170. Line 1 Incorrect syntax near create_journal_entry The stored Procedure begins as follows

      ALTER PROCEDURE create_journal_entry
      @eom_date DATETIME --End of month date
      AS

      DECLARE

      @next_jrnl_num VARCHAR(20)

      The c# code is

      private void createJEs()
      {
      DateTime cutOffDate;
      cutOffDate=this.dtpCutOffDate.Value;

      SqlConnection conn =new SqlConnection(DBConnection.connectionString());
      conn.Open();
      SqlCommand comm=new SqlCommand("create\_journal\_entry",conn);
          comm.Parameters.Add("@eom\_date",SqlDbtype.DateTime);
          comm.parameters\[“@eom\_date”\].value=this.dtpCutOffDate.Value;
      
          try
      {
      	comm.ExecuteNonQuery();	
      	moveFiles();
                  MessageBox.Show("Data has been successfully sent to the   
                  GL.", "Success",MessageBoxButtons.YesNo,MessageBoxIcon.Information);
      }
      catch(SqlException ex)
      {
              MessageBox.Show("Error "+ex.Number + " "+ ex.Message,"SqlServer 
              error",MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
      }
      catch(Exception ex)
      {
              MessageBox.Show(ex.Message,"System Error",  
              MessageBoxButtons.OK,MessageBoxIcon.Exclamation);
      }
      finally
      {
      	if (conn!=null)
      	{
      		conn.Close();
      	}
      }
      

      }

      NB this.dtpCutOffDate is a DateTime picker control. Please help as I am going nuts over this. Thanks

      I Offline
      I Offline
      Ian McCaul
      wrote on last edited by
      #2

      You have to set your command object to stored proc type. i.e. After this line SqlCommand comm=new SqlCommand("create_journal_entry",conn); Type this comm.CommandType = CommandType.StoredProcedure The default is text so it is reading 'create_journal_entry' as your query.

      S 1 Reply Last reply
      0
      • I Ian McCaul

        You have to set your command object to stored proc type. i.e. After this line SqlCommand comm=new SqlCommand("create_journal_entry",conn); Type this comm.CommandType = CommandType.StoredProcedure The default is text so it is reading 'create_journal_entry' as your query.

        S Offline
        S Offline
        SilimSayo
        wrote on last edited by
        #3

        Thanks a batch! It worked right away......just wondering why the heck I could not see that. Feels like Friday.

        1 Reply Last reply
        0
        Reply
        • Reply as topic
        Log in to reply
        • Oldest to Newest
        • Newest to Oldest
        • Most Votes


        • Login

        • Don't have an account? Register

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • World
        • Users
        • Groups