扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:Bipin Joshi 来源:论坛整理 2007年11月5日
关键字: ASP.NET ReportViewer 控件 Windows
using System; using System.Data; using System.Configuration; using System.Data.SqlClient; using System.Collections.Generic; namespace ReportViewerLib { public class Customer { public string strCustomerID; public string strCompanyName; public string strContactName; public string strCountry; public string CustomerID { get { return strCustomerID; } set { strCustomerID = value; } } public string CompanyName { get { return strCompanyName; } set { strCompanyName= value; } } public string ContactName { get { return strContactName; } set { strContactName= value; } } public string Country { get { return strCountry; } set { strCountry= value; } } public static List<Customer> GetCustomersForCountry(string country) { SqlConnection cnn=new SqlConnection( ConfigurationManager.ConnectionStrings["NorthwindConnectionString"].ConnectionString); SqlCommand cmd=new SqlCommand(); cmd.Connection=cnn; cmd.CommandText="select CustomerID,CompanyName,ContactName,Country from customers where country=@country"; SqlParameter p=new SqlParameter ("@country",country); cmd.Parameters.Add(p); cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); List<Customer> list = new List<Customer>(); while (reader.Read()) { Customer c = new Customer(); c.CustomerID = reader.GetString(0); c.CompanyName = reader.GetString(1); c.ContactName = reader.GetString(2); c.Country = reader.GetString(3); list.Add(c); } cnn.Close(); return list; } public static List<Customer> GetAllCustomers() { SqlConnection cnn = new SqlConnection( ConfigurationManager.ConnectionStrings ["NorthwindConnectionString"].ConnectionString); SqlCommand cmd = new SqlCommand(); cmd.Connection = cnn; cmd.CommandText = "select CustomerID,CompanyName,ContactName,Country from customers"; cnn.Open(); SqlDataReader reader = cmd.ExecuteReader(); List<Customer> list = new List<Customer>(); while (reader.Read()) { Customer c = new Customer(); c.CustomerID = reader.GetString(0); c.CompanyName = reader.GetString(1); c.ContactName = reader.GetString(2); c.Country = reader.GetString(3); list.Add(c); } cnn.Close(); return list; } } } |
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者