使用DataProviderSelect

  1. DataProviders.IDataProvider provider = CreateDataProvider();  
  2. provider.SQL = "SELECT CompanyID as [Identity],Name,ShortName,Code,LegalEntity,Address,PostalCode,Type as CompanyType,CityID,Version " +  
  3. "FROM lt_dictionary.Company WHERE CityID=@cityid";  
  4. provider.AddParameters("@cityid", cityID);  
  5. return provider.ExecuteDataTable(); 

使用DataProviderUpdate

  1. DataProviders.IDataProvider provider = CreateDataProvider();  
  2. provider.SQL = "UPDATE lt_dictionary.Company " +  
  3. "SET " +  
  4. "Name=@name, " +  
  5. "ShortName=@shortName," +  
  6. "Code=@code," +  
  7. "LegalEntity=@legalEntity," +  
  8. "Address=@address," +  
  9. "PostalCode=@postalCode, " +  
  10. "Type=@type," +  
  11. "CityID=@cityID " +  
  12. "WHERE CompanyID=@id AND Version=@ver";  
  13. provider.AddParameters("@name", company.Name);  
  14. provider.AddParameters("@shortName", company.ShortName);  
  15. provider.AddParameters("@Code", company.Code);  
  16. provider.AddParameters("@LegalEntity", company.LegalEntity);  
  17. provider.AddParameters("@address", company.Address);  
  18. provider.AddParameters("@postalCode", company.PostalCode);  
  19. provider.AddParameters("@type", company.CompanyType.ToString());  
  20. provider.AddParameters("@cityID", company.City.Identity);  
  21. provider.AddParameters("@id", original_company.Identity);  
  22. provider.AddParameters("@ver", original_company.Version, DataProviders.ByteArrayFamily.Timestamp);  
  23. return provider.ExecuteNonQuery() > 0; 

 

 

使用DataProviderInsert

  1. DataProviders.IDataProvider provider = CreateDataProvider();  
  2. provider.SQL = "INSERT INTO lt_dictionary.City " +  
  3. "([Name],PostalCode,DistanceCode,Province,Longitude,Latitude)" +  
  4. "VALUES " +  
  5. "(@Name,@PostalCode,@DistanceCode,@Province,@Longitude,@Latitude)";  
  6. provider.AddParameters("@name", city.Name);  
  7. provider.AddParameters("@postalCode", city.PostalCode);  
  8. provider.AddParameters("@distanceCode", city.DistanceCode);  
  9. provider.AddParameters("@province", city.Province);  
  10. provider.AddParameters("@longitude", city.Longitude);  
  11. provider.AddParameters("@latitude", city.Latitude);  
  12. return provider.ExecuteNonQuery() > 0; 

 

 

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