|
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Services;
using System.Data.SqlClient;
using System.Configuration;
/// <summary>
/// Summary description for WebService
/// </summary>
[WebService(Namespace = "http://tempuri.org/")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
// To allow this Web Service to be called from script, using ASP.NET AJAX, uncomment the following line.
[System.Web.Script.Services.ScriptService]
public class WebService : System.Web.Services.WebService {
public class CollectData
{
public string cost { get; set; }
public string imagePath { get; set; }
public string description { get; set; }
}
public WebService () {
}
[WebMethod()]
public CollectData GetDetails(string name)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString);
SqlCommand cmd = new SqlCommand("Select cost, imagePath, description from Products where ProductId='" + name + "'",con);
SqlDataReader data;
CollectData c = new CollectData();
try
{
con.Open();
data=cmd.ExecuteReader();
if (data.Read())
{
c.cost= data[0].ToString();
c.imagePath = data[1].ToString();
c.description = data[2].ToString();
return c;
}
else
{
c.cost = "N/A";
c.imagePath = "N/A";
c.description = "N/A";
return c;
}
}
catch (Exception ex)
{
c.cost = "N/A";
c.imagePath = "N/A";
c.description = "N/A";
return c;
}
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.