CascadingDropDown控件读数据库不出东西
using System;
using System.Web;
using System.Collections;
using System.Configuration;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Web.Services;
using System.Web.Services.Protocols;
using AjaxControlToolkit;
using System.Data;
using System.Data.SqlClient;
/**/
/// <summary>
/// Summary description for Northwind
/// </summary>
[WebService(Namespace = "http://tempuri.org/ ")]
[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)]
[System.Web.Script.Services.ScriptService]
public class Northwind : System.Web.Services.WebService
{
public Northwind()
{
}
[WebMethod]
public CascadingDropDownNameValue[] GetEmployees(string knownCategoryValues, string category)
{
string connectionString = ConfigurationManager.ConnectionStrings[ "Northwind "].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand( "SELECT * FROM Employees ");
command.Connection = connection;
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
command.Connection.Close();
DataTable tbl = dataSet.Tables[0];
List <CascadingDropDownNameValue> values = new List <CascadingDropDownNameValue> ();
foreach (DataRow dr in tbl.Rows)
{
string sEmployee = (string)dr[ "FirstName "] + " " +dr[ "LastName "];
int iEmployee = (int)dr[ "EmployeeID "];
values.Add(new CascadingDropDownNameValue(sEmployee, iEmployee.ToString()));
}
return values.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetOrdersByEmployee(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int iEmployee;
if (!kv.ContainsKey( "Employee ") || !Int32.TryParse(kv[ "Employee "], out iEmployee))
{
return null;
}
string connectionString = ConfigurationManager.ConnectionStrings[ "Northwind "].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand( "SELECT OrderID FROM Orders WHERE EmployeeID = " + iEmployee);
command.Connection = connection;
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
command.Connection.Close();
DataTable tbl = dataSet.Tables[0];
List <CascadingDropDownNameValue> values = new List <CascadingDropDownNameValue> ();
foreach (DataRow dr in tbl.Rows)
{
string sOrder = dr[ "OrderID "].ToString();
int iOrder = (int)dr[ "OrderID "];
values.Add(new CascadingDropDownNameValue(sOrder, iOrder.ToString()));
}
return values.ToArray();
}
[WebMethod]
public CascadingDropDownNameValue[] GetDetailsByOrder(string knownCategoryValues, string category)
{
StringDictionary kv = CascadingDropDown.ParseKnownCategoryValuesString(knownCategoryValues);
int iOrder;
if (!kv.ContainsKey( "Order ") || !Int32.TryParse(kv[ "Order "], out iOrder))
{
return null;
}
string connectionString = ConfigurationManager.ConnectionStrings[ "Northwind "].ConnectionString;
SqlConnection connection = new SqlConnection(connectionString);
SqlCommand command = new SqlCommand( "SELECT UnitPrice,OrderID FROM [Order Details] WHERE OrderID = " + iOrder);
command.Connection = connection;
connection.Open();
SqlDataAdapter adapter = new SqlDataAdapter(command);
DataSet dataSet = new DataSet();
adapter.Fill(dataSet);
command.Connection.Close();
DataTable tbl = dataSet.Tables[0];
List <CascadingDropDownNameValue> values = new List <CascadingDropDownNameValue> ();
foreach (DataRow dr in tbl.Rows)
{
string UnitPrice = dr[ "UnitPrice "].ToString();
int intOrder = (int)dr[ "OrderID "];
values.Add(new CascadingDropDownNameValue(UnitPrice, intOrder.ToString()));
}
return values.ToArray();
}
}
[解决办法]
呃 好多代码