Skip to content

Instantly share code, notes, and snippets.

@A2H111
Created August 13, 2016 13:41
Show Gist options
  • Save A2H111/7873e61810fb349828e47137ce6e2f29 to your computer and use it in GitHub Desktop.
Save A2H111/7873e61810fb349828e47137ce6e2f29 to your computer and use it in GitHub Desktop.
//Method to populate the Initial Dropdownlist
[System.Web.Services.WebMethod()]
public static List<OrderList> GetProductList()
{
List<OrderList> list = new List<OrderList>();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NORTHWINDConnectionString"].ConnectionString))
{
conn.Open();
string strquery = "Select TOP 10 * from Orders";
using (SqlCommand cmd = new SqlCommand(strquery, conn))
{
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
OrderList objorder = new OrderList(int.Parse(reader["OrderID"].ToString()), reader["ShipAddress"].ToString(), reader["ShipName"].ToString(), double.Parse(reader["Freight"].ToString()));
list.Add(objorder);
}
}
}
return list;
}
[System.Web.Services.WebMethod()]
public static List<CustomerList> GetCustomerList(int orderID)
{
List<CustomerList> list = new List<CustomerList>();
using (SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["NORTHWINDConnectionString"].ConnectionString))
{
conn.Open();
string strquery = "Select CustomerID from Orders where OrderID = @orderID";
using (SqlCommand cmd = new SqlCommand(strquery, conn))
{
cmd.Parameters.AddWithValue("@orderID", orderID);
SqlDataReader reader = cmd.ExecuteReader();
while (reader.Read())
{
CustomerList objorder = new CustomerList(reader["CustomerID"].ToString());
list.Add(objorder);
}
}
}
return list;
}
public class CustomerList
{
public string CustomerName;
public CustomerList(string customerName)
{
CustomerName = customerName;
}
}
public class OrderList
{
public int OrderID;
public string ShipName;
public string ShipAddress;
public double Freight;
public OrderList(int orderID, string shipName, string shipAddress, double freight)
{
OrderID = orderID;
ShipName = shipName;
ShipAddress = shipAddress;
Freight = freight;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment