Click here to Skip to main content
16,019,085 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Everyone,

i am Trying to Make TEXT Box Who Search data From The Database on Website.i am still Face One Error.
Error: "Compiler Error Message: CS1061: 'string' does not contain a definition for 'Title' and no extension method 'Title' accepting a first argument of type 'string' could be found (are you missing a using directive or an assembly reference?)"

.Please See the Code and tell me Where is The Problem.

C#
@{
    //var PostID=Request.QueryString["Postid"];<a href="Default.cshtml"></a>
    int ID=0;
    var Post="";
    var PostID=Request.Form["Search"];
    if(!PostID.IsEmpty() && PostID.IsInt())
    {
        ID=Convert.ToInt32(PostID);
    }
        var Db=Database.Open("Lesson1");
    //var Post=Db.QuerySingle("Select * From BlogPosts Where ID=@0 And DatePublished<getdate()",ID);
    Post=Db.QuerySingle("Select * From BlogPosts Where Id=@0 And DatePublished<getdate()",ID);
  }

<!DOCTYPE html>

<html lang="en">
    <head>
        <meta charset="utf-8" />
        <title></title>
    </head>
    <body>
        <form action="" method="post">
            <label for="Search">Search:</label>
            <input type="search" placeholder="Enter Post ID" name="Search" value="">
            <input type="submit" value="Submit">
       </form>
    @if(Post!=null)
    {
            <div>
                <h1>@Post.Title</h1>
                <p>@Html.Raw(Post.Content)</p>
            </div>
    }
    else
    {
        <p>Not Blog Post Is Found</p>
    }
    </body>
</html>
Posted
Updated 13-Feb-15 8:02am
v2

1 solution

You've declared the variable Post as a string:
C#
var Post="";

Remove that line, and use:
C#
var Post = Db.QuerySingle("Select * From BlogPosts Where Id=@0 And DatePublished < getdate()", ID);
 
Share this answer
 
Comments
Member 11004573 13-Feb-15 15:39pm    
I Did This but i faced different error that "Post is not Accessible in this Scope(Html Body Scope),Please Tell me Another Better Solution.
Richard Deeming 13-Feb-15 15:56pm    
The code in your question should not produce that error. Use the "Improve question" link to update the question with your current code.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900