Click here to Skip to main content
15,900,815 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I'm working with a project there i have a WCF Library, Empty SharePoint project and i've added a Visual Web Part.

I got one TextBox_Search and some other textboxes like, TextBox_Name.

I want to search in my Database with my TextBox_Search and then display the name value from my Database in my TextBox_Name, Color, etc...

Here's some code i'm using:


public Product GetProduct(int id)
using (var db = new AdventureWorks2008Entities())
var productEntitie = (from data in db.ProductEntities
where data.ProductID == id
select data).FirstOrDefault();

if (productEntitie != null)
return TranslateProductEntityToProduct(productEntitie);
throw new Exception("Invalid product id");

private Product TranslateProductEntityToProduct(ProductEntity productEntity)
var prod = new Product
ProductName = productEntity.Name,
ProductID = productEntity.ProductID,
ProductNumber = productEntity.ProductNumber,
ListPrice = productEntity.ListPrice,
Color = productEntity.Color

return prod;


public interface IProductService
Product GetProduct(int id);

// Use a data contract as illustrated in the sample below to add composite types to service operations
public class Product
public int ProductID { get; set; }

public string ProductNumber { get; set; }

public decimal ListPrice { get; set; }

public string ProductName { get; set; }

public string Color { get; set; }

In my SharePoint project:
protected void Page_Load(object sender, EventArgs e)

protected void Button_Search_Click(object sender, EventArgs e)
var srvRef = new ServiceReference1.Product();

//Here's my problem. When i type:
// TextBox_Search.Text = srvRef.ProductID.ToString(TextBox_Name.Text);
// I get value 0 in my TextBox_Search, not Name.

Thanks and hope to hear from you!

Kind regards,

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