We're a community of 1.1M IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,080,440 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

Delete db record using Razor syntax

Hello,

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;
	if(IsPost)
		{
			var SQLDELETE = "DELETE FROM Names WHERE ID=@0";
			db.Execute(SQLDELETE, id);
			Response.Redirect("Default.cshtml");
		}
}
<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'" />
</form>

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

1
Contributor
0
Replies
1
View
UFO Disko
Newbie Poster
20 posts since Feb 2012
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
View similar articles that have also been tagged:
 
© 2013 DaniWeb® LLC
Page generated in 0.0618 seconds using 2.87MB