@{
Layout = "~/_SiteLayout.cshtml";
Page.Title = "Edit Movie";
var id = Request["MovieID"];
var SQLSELECT = "SELECT * FROM Names where MovieID=@0";
var db = Database.Open("Movies");
var Movies = db.QuerySingle(SQLSELECT, movie.MovieID);
var MovieName = movie.MovieName;
var MovieGenre = movie.MovieGenre;
if (IsPost)
{
MovieName=Request["formName"];
MovieGenre = Request["formGenre"];
var SQLUPDATE = "UPDATE Favorites SET MovieName=@0, MovieGenre=@1 where MovieID=@2";
db.Execute(SQLUPDATE, MovieName, MovieGenre, id);
}
}
<h3>Edit Movie</h3>
<form action="" method="post">
<p>Name:<br /><input type="text" name="formName" value="@MovieName"></p>
<p>Genre:<br /><input type="text" name="formGenre" value="@MovieGenre"></p>
<p><input type="submit" value="Edit Movie"/></p>
</form>
And I'm getting this error
Compilation Error
Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.
Compiler Error Message: CS0103: The name 'movie' does not exist in the current context
Source Error:
Line 6: var SQLSELECT = "SELECT * FROM Names where MovieID=@0";
Line 7: var db = Database.Open("Movies");
Line 8: var Movies = db.QuerySingle(SQLSELECT, @movie.MovieID);
Line 9: var MovieName = movie.MovieName;
Line 10: var MovieGenre = movie.MovieGenre;
Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\EditMovie.cshtml Line: 8
Please note that on Default.cshtml I'm able to fetch the data records using @movie.MovieName and @movie.MovieGenre (these are the only records I have apart from the movie.MovieID)
Please advise and sorry again for the repost, please don't ban me :(
var Movies = db.QuerySingle(SQLSELECT, movie.MovieID);
There's your problem. You assigned the query result to a variable named Movies with a capital M. Change that to movie, or your assignment statements as follows:
var MovieName = Movies.MovieName;
var MovieGenre = Movies.MovieGenre;
Compiler Error Message: CS0841: Cannot use local variable 'Movies' before it is declared
Source Error:
Line 6: var SQLSELECT = "SELECT * FROM Names where MovieID=@0";
Line 7: var db = Database.Open("Movies");
Line 8: var Movies = db.QuerySingle(SQLSELECT, Movies.MovieID);
Line 9: var MovieName = Movies.MovieName;
Line 10: var MovieGenre = Movies.MovieGenre;
Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\EditMovie.cshtml Line: 8
var SQLSELECT = "SELECT * FROM Names where MovieID=@0";
var db = Database.Open("Movies");
var Movies = db.QuerySingle(SQLSELECT, id);
var MovieName = Movies.MovieName;
var MovieGenre = Movies.MovieGenre;
Exception Details: System.ArgumentNullException: Parameterized query expects a parameter value which was not supplied.
Parameter name: 0
Source Error:
Line 6: var SQLSELECT = "SELECT * FROM Names where MovieID=@0";
Line 7: var db = Database.Open("Movies");
Line 8: var Movies = db.QuerySingle(SQLSELECT, id);
Line 9: var MovieName = Movies.MovieName;
Line 10: var MovieGenre = Movies.MovieGenre;
Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\EditMovie.cshtml Line: 8
That means you haven't got a value in Request["MovieID"]. I haven't seen the tutorial, but I guess you have a page with links that point to EditMovie.cshtml? If so, you need to add a querystring value to your request eg EditMovie.cshtml?MovieID=1,
or go to the page with the links first and click one.
One last question. When I add a new movie to the database, the 2 text fields I have should be empty, but instead when I click inside "Genre" it shows that there are blank characters already there.
So when I enter for example "Drama" in the database it gets submitted as this "Drama "
UFO Disko
Member
51 Points
50 Posts
The name 'movie' does not exist in the current context
Mar 01, 2012 11:39 AM|LINK
Hello,
Sorry for reposting but I can't access or read my previous thread, it's showing under the name "Unknown" and if you click on it, it's blank.
Anyway, I'm following the video tutorials here to create a simple edit page.
http://www.asp.net/web-pages/videos/introduction/create-an-edit-data-page-in-webmatrix
This is my code
@{ Layout = "~/_SiteLayout.cshtml"; Page.Title = "Edit Movie"; var id = Request["MovieID"]; var SQLSELECT = "SELECT * FROM Names where MovieID=@0"; var db = Database.Open("Movies"); var Movies = db.QuerySingle(SQLSELECT, movie.MovieID); var MovieName = movie.MovieName; var MovieGenre = movie.MovieGenre; if (IsPost) { MovieName=Request["formName"]; MovieGenre = Request["formGenre"]; var SQLUPDATE = "UPDATE Favorites SET MovieName=@0, MovieGenre=@1 where MovieID=@2"; db.Execute(SQLUPDATE, MovieName, MovieGenre, id); } } <h3>Edit Movie</h3> <form action="" method="post"> <p>Name:<br /><input type="text" name="formName" value="@MovieName"></p> <p>Genre:<br /><input type="text" name="formGenre" value="@MovieGenre"></p> <p><input type="submit" value="Edit Movie"/></p> </form>And I'm getting this error
Compilation Error Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately. Compiler Error Message: CS0103: The name 'movie' does not exist in the current context Source Error: Line 6: var SQLSELECT = "SELECT * FROM Names where MovieID=@0"; Line 7: var db = Database.Open("Movies"); Line 8: var Movies = db.QuerySingle(SQLSELECT, @movie.MovieID); Line 9: var MovieName = movie.MovieName; Line 10: var MovieGenre = movie.MovieGenre; Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\EditMovie.cshtml Line: 8Please note that on Default.cshtml I'm able to fetch the data records using @movie.MovieName and @movie.MovieGenre (these are the only records I have apart from the movie.MovieID)
Please advise and sorry again for the repost, please don't ban me :(
records data
bbcompent1
All-Star
32978 Points
8502 Posts
Moderator
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 11:46 AM|LINK
Ok, try the most simple fix first, change movie to Movie just in case its capitalized somewhere else in your code.
records data
UFO Disko
Member
51 Points
50 Posts
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 11:50 AM|LINK
I already tried that, and I got the same error
Note on Default.cshtml this is the foreach loop
@foreach (var movie in movies) { <li><a href="EditMovie.cshtml?id=@movie.MovieID">@movie.MovieName - @movie.MovieGenre</a></li> }And it works without a problem there.
records data
Mikesdotnett...
All-Star
154852 Points
19855 Posts
Moderator
MVP
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 12:27 PM|LINK
There's your problem. You assigned the query result to a variable named Movies with a capital M. Change that to movie, or your assignment statements as follows:
var MovieName = Movies.MovieName;
var MovieGenre = Movies.MovieGenre;
records data
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
UFO Disko
Member
51 Points
50 Posts
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 03:56 PM|LINK
Now I'm getting the following error
Compiler Error Message: CS0841: Cannot use local variable 'Movies' before it is declared Source Error: Line 6: var SQLSELECT = "SELECT * FROM Names where MovieID=@0"; Line 7: var db = Database.Open("Movies"); Line 8: var Movies = db.QuerySingle(SQLSELECT, Movies.MovieID); Line 9: var MovieName = Movies.MovieName; Line 10: var MovieGenre = Movies.MovieGenre; Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\EditMovie.cshtml Line: 8records data
Mikesdotnett...
All-Star
154852 Points
19855 Posts
Moderator
MVP
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 04:21 PM|LINK
var SQLSELECT = "SELECT * FROM Names where MovieID=@0"; var db = Database.Open("Movies"); var Movies = db.QuerySingle(SQLSELECT, id); var MovieName = Movies.MovieName; var MovieGenre = Movies.MovieGenre;Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
UFO Disko
Member
51 Points
50 Posts
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 04:25 PM|LINK
Exception Details: System.ArgumentNullException: Parameterized query expects a parameter value which was not supplied. Parameter name: 0 Source Error: Line 6: var SQLSELECT = "SELECT * FROM Names where MovieID=@0"; Line 7: var db = Database.Open("Movies"); Line 8: var Movies = db.QuerySingle(SQLSELECT, id); Line 9: var MovieName = Movies.MovieName; Line 10: var MovieGenre = Movies.MovieGenre; Source File: c:\Users\utopicvision\Documents\My Web Sites\DemoSite\EditMovie.cshtml Line: 8Mikesdotnett...
All-Star
154852 Points
19855 Posts
Moderator
MVP
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 04:32 PM|LINK
That means you haven't got a value in Request["MovieID"]. I haven't seen the tutorial, but I guess you have a page with links that point to EditMovie.cshtml? If so, you need to add a querystring value to your request eg EditMovie.cshtml?MovieID=1, or go to the page with the links first and click one.
Beginning ASP.NET Web Pages with WebMatrix | My Site | Twitter
UFO Disko
Member
51 Points
50 Posts
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 04:46 PM|LINK
Thank you. I can't believe I missed that.
One last question. When I add a new movie to the database, the 2 text fields I have should be empty, but instead when I click inside "Genre" it shows that there are blank characters already there.
So when I enter for example "Drama" in the database it gets submitted as this "Drama "
The type of that data field is "nchar"
bbcompent1
All-Star
32978 Points
8502 Posts
Moderator
Re: The name 'movie' does not exist in the current context
Mar 01, 2012 04:48 PM|LINK
You probably could use trim to remove the extra padding when you do your db insert.