0
votes

how can i use request.querystring in asp.net. I am trying to retrieve data using Linq but I keep getting errors. Please get back to me Asap. Im still a novice in asp.net Code behind:

      BlogDBDataContext db = new BlogDBDataContext();

        dynamic q = from b in db.Blogs
                    where b.BlogId = Request.QueryString("BlogId") 
                    select  b;


        lv.DataSource = q;
        lv.DataBind();

this give me the error that says : Non-invocable member 'System.Web.HttpRequest.QueryString' cannot be used like a method.

Code behind: even when I try this code : Request.QueryString["BlogId"]

still it gives me an error : Cannot implicitly convert type 'string' to 'int'

1

1 Answers

0
votes

QueryString is a NameValueCollection, not a method - you should use the [] operator to access members:

Request.QueryString["BlogId"]

Edit: just read the rest of your question. The value of Request.QueryString["BlogId"] is a string, not an int, as the error message suggests. I assume that b.BlogId is an int, so you need to parse the string to an int first.

BlogDBDataContext db = new BlogDBDataContext();

int blogId;
if (int.TryParse(Request.QueryString["BlogId"], out blogId))
{
    dynamic q = from b in db.Blogs
                where b.BlogId == blogId 
                select b;

    lv.DataSource = q;
    lv.DataBind();
}