SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Mar 2013
    Posts
    64
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Help needed with inserting a row into MS SQL Compact using razor MS Web Matrix c#

    Hi

    This is my first attempt at trying to insert a row into a table using this code but get the compilation error below if anyone can help me please. The code is :-

    @{
    var db = Database.Open("MatrixMan");
    var titleEntry = Response["title"];
    var notesEntry = Response["notes"];
    var imageEntry = Response["image"];

    if (IsPost){
    var insertQ = "INSERT INTO Journal (DateCreate, DateEdit, Title, Notes, Image) VALUES (@1,@2,@3,@4,@5)";
    db.Execute(insertQ,
    DateTime.Now.ToLongDateString, DateTime.Now.ToLongDateString, titleEntry, notesEntry, imageEntry);
    Response.Redirect(@Href("~/index.html"));
    }
    }

    <!DOCTYPE html>
    <html lang="en">
    <head>
    <meta charset="utf-8" />
    <title>The Matrix Man</title>
    <link href="StyleSheet1.css" rel="stylesheet" type="text/css" />
    </head>
    <body>
    <div id="header">
    </div> <!-- end of header div -->

    <div id="bodycontent">
    <form action="" method="post">
    Title <input type="text" name="title" tabindex="1" value="@title"></input>
    <br />
    Notes <input type="text" name="notes" tabindex="1" value="@notes"></input>
    <br />
    Image <input type="text" name="image" tabindex="3" value="@image"></input>
    <br />
    <input type="submit" value="Insert" name="Submit"></input>
    </form>
    </div> <!-- end of bodycontent div -->

    </body>
    </html>I get this error. I followed another book which implied that I use the value keyword but this made no difference. I still get the same error :-

    Server Error in '/' Application.

    --------------------------------------------------------------------------------
    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: CS0021: Cannot apply indexing with [] to an expression of type 'System.Web.HttpResponseBase'
    Source Error:

    Line 1: @{
    Line 2: var db = Database.Open("MatrixMan");
    Line 3: var titleEntry = Response["title"];
    Line 4: var notesEntry = Response["notes"];
    Line 5: var imageEntry = Response["image"];

    Source File: c:\Users\CATSPC5\Documents\My Web Sites\MatrixMan\inputjournalentry.cshtml Line: 3

    Much appreciated if someone could help me on my way please.

    Kind Regards

    Matt

    p.s even if I delete line 3, then I just get the same error affecting line 4

  2. #2
    SitePoint Author silver trophybronze trophy
    wwb_99's Avatar
    Join Date
    May 2003
    Location
    Washington, DC
    Posts
    10,653
    Mentioned
    4 Post(s)
    Tagged
    0 Thread(s)
    Response doesn't have an indexer. You probably want to use Request.

  3. #3
    SitePoint Enthusiast
    Join Date
    Mar 2013
    Posts
    64
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thanks, actually there the code was fine. I rebooted my PC a day later and it worked fine!!!

    Cheers
    Matt


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •