Text data types and nvarchar are incompatible in equal operator

this is my code

ProductController.cs

public ActionResult Details(string id)
{
    product productx = productDB.products.Single(pr => pr.Product1 == id);
    return View(productx);


}

Details.aspx

    <td>
        <%-- : Html.ActionLink("Edit", "Edit", new { id=item.Id }) % --> 
        <%: Html.ActionLink("Details", "Details", new { id = item.Product1 })%>
    </td>

this is what im uses to list some products from sql database, each product has a link to the details page to show more information about it

what I'm trying is only to put the product label in this link so that it displays something like www.mysite.com \ products \ battery (and not id)

I assumed that this should work, but it throws text data types and nvarchar are incompatible with the equal operator. error and neither (pr => pr.Product1.Equals(id));works

the error is clear, and I ask how can I make it work that way?

thank

+5
2

TEXT SQL Server / . . , .

varchar(max), , . Linq to SQL, .

, ... ID TEXT varchar(max), GUID (uniqueidentifier), . , , , .

+22

:

Exemple

string sql = "Select * from TB_USER where Name = @Name";
SqlCommand cmd = new SqlCommand(sql);

:

cmd.Parameters.Add("@Nome", SqlDbType.Text).Value = nome;

:

cmd.Parameters.Add("@Nome", SqlDbType.VarChar, 50).Value = nome;
0

All Articles