zoukankan      html  css  js  c++  java
  • 使用我们的DataProvider

    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指令和参数的赋值,其他内容不再需要其关注。很高程度的提高了程序员的开发效率。

  • 相关阅读:
    GPS精度因子(GDOP,PDOP,HDOP,VDOP,TDOP)
    VTD专题
    使用Python的Numpy 生成随机数列表
    Win10 下使用Ubuntu子系统
    Python依赖库查找
    使用技巧
    openstreetmap算路服务搭建
    笔记
    markdownpad
    缓和曲线09正弦一波型
  • 原文地址:https://www.cnblogs.com/shyleoking/p/1336556.html
Copyright © 2011-2022 走看看