安忍不动如大地,静虑深思如秘藏
雄鹰虽然有时候飞的比鸡还低 但鸡永远也不可能飞到鹰的高度

1.8使用DataProvider

 

 

使用DataProviderSelect

DataProviders.IDataProvider provider = CreateDataProvider();

provider.SQL = "SELECT CompanyID as [Identity],Name,ShortName,Code,LegalEntity,Address,PostalCode,Type as CompanyType,CityID,Version " +

                "FROM lt_dictionary.Company WHERE CityID=@cityid";

provider.AddParameters("@cityid", cityID);

 

return provider.ExecuteDataTable();

 

 

 

使用DataProviderUpdate

DataProviders.IDataProvider provider = CreateDataProvider();

provider.SQL = "UPDATE lt_dictionary.Company " +

                "SET " +

                "Name=@name, " +

                "ShortName=@shortName," +

                "Code=@code," +

                "LegalEntity=@legalEntity," +

                "Address=@address," +

                "PostalCode=@postalCode, " +

                "Type=@type," +

                "CityID=@cityID " +

                "WHERE CompanyID=@id AND Version=@ver";

 

provider.AddParameters("@name", company.Name);

provider.AddParameters("@shortName", company.ShortName);

provider.AddParameters("@Code", company.Code);

provider.AddParameters("@LegalEntity", company.LegalEntity);

provider.AddParameters("@address", company.Address);

provider.AddParameters("@postalCode", company.PostalCode);

provider.AddParameters("@type", company.CompanyType.ToString());

provider.AddParameters("@cityID", company.City.Identity);

provider.AddParameters("@id", original_company.Identity);

provider.AddParameters("@ver", original_company.Version, DataProviders.ByteArrayFamily.Timestamp);

 

return provider.ExecuteNonQuery() > 0;

 

 

 

使用DataProviderInsert

DataProviders.IDataProvider provider = CreateDataProvider();

provider.SQL = "INSERT INTO lt_dictionary.City " +

                "([Name],PostalCode,DistanceCode,Province,Longitude,Latitude)" +

                "VALUES " +

                "(@Name,@PostalCode,@DistanceCode,@Province,@Longitude,@Latitude)";

provider.AddParameters("@name", city.Name);

provider.AddParameters("@postalCode", city.PostalCode);

provider.AddParameters("@distanceCode", city.DistanceCode);

provider.AddParameters("@province", city.Province);

provider.AddParameters("@longitude", city.Longitude);

provider.AddParameters("@latitude", city.Latitude);

 

return provider.ExecuteNonQuery() > 0;

 

 

通过上述的代码,可以发现,使用了我们的DataProvider后,程序员对ADO.Net的了解被降到最低程度,其只要关心具体的SQL指令和参数的赋值,其他内容不再需要其关注。很高程度的提高了程序员的开发效率。

posted on 2008-11-19 12:57  害羞的狮子王  阅读(606)  评论(0编辑  收藏  举报