1,105,225 Community Members

Delete db record using Razor syntax

Member Avatar
UFO Disko
Newbie Poster
20 posts since Feb 2012
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]


I'm currently following the video tutorials found on asp.net (the site)\
And I just finished my delete page but I'm getting errors.

This is the code of the page DeleteMovie.cshtml

    Layout = "~/_SiteLayout.cshtml";
	var id = Request["MovieID"];
	var SQLSELECT = "SELECT * FROM Names where MovieID=@0";
	var db = Database.Open("Movies");
	var Movie = db.QuerySingle(SQLSELECT, id);
	var MovieName = Movie.MovieName;
			db.Execute(SQLDELETE, id);
<h1>Delete Movie</h1>
<p>Are you sure you want to delete <b>@Movie.MovieName</b>?
<form action="" method="post">
	<input type="submit" value="Yes" />
	<input type="button" value="No" onclick="window.location = 'Default.cshtml'" />

And this is the error I'm receiving

The column name is not valid. [ Node name (if any) = ,Column name = ID ]

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.SqlServerCe.SqlCeException: The column name is not valid. [ Node name (if any) = ,Column name = ID ]

Source Error: 

Line 10: 		{
Line 11: 			var SQLDELETE = "DELETE FROM Names WHERE ID=@0";
Line 12: 			db.Execute(SQLDELETE, id);
Line 13: 			Response.Redirect("Default.cshtml");
Line 14: 		}

Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\DeleteMovie.cshtml    Line: 12

What am I doing wrong here?
I only have 1 table and 3 fields in my database: MovieID, MovieName, MovieGenre

This article has been dead for over three months: Start a new discussion instead
Start New Discussion
View similar articles that have also been tagged: