Click here to Skip to main content
15,905,148 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi!
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:

WCF:
Service1.cs:

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);
else
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;
}


IService.cs:

public interface IProductService
{
[OperationContract]
Product GetProduct(int id);
}

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

[DataMember]
public string ProductNumber { get; set; }

[DataMember]
public decimal ListPrice { get; set; }

[DataMember]
public string ProductName { get; set; }

[DataMember]
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,
Kristian.
Posted

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