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. Database & SysAdmin
  3. Database
  4. C# DELETE FROM Parameter problem

C# DELETE FROM Parameter problem

Scheduled Pinned Locked Moved Database
databasehelpcsharpcomsecurity
2 Posts 2 Posters 1 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.
  • M Offline
    M Offline
    Magnus Vinterhav
    wrote on last edited by
    #1

    Hi. I have a local db with a number of tables. One is a table with filenames. This method is supposed to remove the file from the database table HiddenFile with the id sent to the method. I have been trying to solve this for a long time without success. The code is:

    	public bool DeleteFile(Int32 identity)
    	{
    		string connString = "Data Source=(LocalDB)\\\\MSSQLLocalDB;AttachDbFilename=C:\\\\Code\\\\FileDB.mdf;Integrated Security=True;Connect Timeout=30";
    
    		SqlConnection dbConn = new SqlConnection(connString);
    		dbConn.Open();
    
    		using (SqlCommand com = new SqlCommand("DELETE FROM HiddenFile WHERE Id = @Identity)", dbConn))
    		{
    			com.Parameters.AddWithValue("@Identity", identity);
    
    			com.ExecuteNonQuery();
    		}
    
    		dbConn.Close();
    
    		return true;
    	}
    

    When I run it, there is an error: "Incorrect syntax near ')'". Can anybody see what the problem is?

    Kornfeld Eliyahu PeterK 1 Reply Last reply
    0
    • M Magnus Vinterhav

      Hi. I have a local db with a number of tables. One is a table with filenames. This method is supposed to remove the file from the database table HiddenFile with the id sent to the method. I have been trying to solve this for a long time without success. The code is:

      	public bool DeleteFile(Int32 identity)
      	{
      		string connString = "Data Source=(LocalDB)\\\\MSSQLLocalDB;AttachDbFilename=C:\\\\Code\\\\FileDB.mdf;Integrated Security=True;Connect Timeout=30";
      
      		SqlConnection dbConn = new SqlConnection(connString);
      		dbConn.Open();
      
      		using (SqlCommand com = new SqlCommand("DELETE FROM HiddenFile WHERE Id = @Identity)", dbConn))
      		{
      			com.Parameters.AddWithValue("@Identity", identity);
      
      			com.ExecuteNonQuery();
      		}
      
      		dbConn.Close();
      
      		return true;
      	}
      

      When I run it, there is an error: "Incorrect syntax near ')'". Can anybody see what the problem is?

      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu PeterK Offline
      Kornfeld Eliyahu Peter
      wrote on last edited by
      #2

      "DELETE FROM HiddenFile WHERE Id = @Identity)" <- you have here an unnecessary closing parenthesis...remove it...

      Skipper: We'll fix it. Alex: Fix it? How you gonna fix this? Skipper: Grit, spit and a whole lotta duct tape.

      "It never ceases to amaze me that a spacecraft launched in 1977 can be fixed remotely from Earth." ― Brian Cox

      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