• 大小: 218KB
    文件类型: .rar
    金币: 1
    下载: 0 次
    发布日期: 2021-05-17
  • 语言: 其他
  • 标签:

资源简介

wcf对数据库的增删改查的综合实例,里面描述了常见的错误处理方式,是学习WCF入门的很不错的实例

资源截图

代码片段和文件信息

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DBModel;

namespace AccessDB
{
    public class DBHelper
    {
        TestEntities dbContext;
        public DBHelper()
        {
            dbContext = new TestEntities();
        }

        public void AddProducts(Products products)
        {
            try
            {
                tb_Products tmp = new tb_Products();
                tmp.ProductID = products.ProductID;
                tmp.ProductName = products.ProductName;
                tmp.ProductOrigin = products.ProductOrigin;
                tmp.ProductCategory = products.ProductCategory;
                dbContext.AddTotb_Products(tmp);
                dbContext.SaveChanges();
            }
            catch
            { 
            }
        }

        public void DelProducts(int productID)
        {
            try
            {
                tb_Products tmp = dbContext.tb_Products.FirstOrDefault(c => c.ProductID == productID);
                dbContext.Deleteobject(tmp);
                dbContext.SaveChanges();
            }
            catch
            { 
            }
        }

        public void UpdateProducts(Products products)
        {
            try
            {
                tb_Products tmp = dbContext.tb_Products.FirstOrDefault(c => c.ProductID == products.ProductID);
                tmp.ProductName = products.ProductName;
                tmp.ProductOrigin = products.ProductOrigin;
                tmp.ProductCategory = products.ProductCategory;
                dbContext.SaveChanges();
            }
            catch
            {
                throw new Exception();
            }
        }

        public Products GetProducts(int productID)
        {
            try
            {
                tb_Products tmp = dbContext.tb_Products.FirstOrDefault(c => c.ProductID == productID);
                Products products = new Products();
                products.ProductID = tmp.ProductID;
                products.ProductName = tmp.ProductName;
                products.ProductOrigin = tmp.ProductOrigin;
                products.ProductCategory = tmp.ProductCategory;
                return products;
            }
            catch
            {
                return null;
            }
        }

        public List GetProductsList()
        {
            try
            {
                List productsList = new List();
                List tb_ProductsList = dbContext.tb_Products.ToList();
                
                if (tb_ProductsList.Count > 0)
                {
                    foreach (tb_Products tmp in tb_ProductsList)
                    {
                        Products products = new Products();
                        products.ProductID = tmp.ProductID;
                        products.ProductName = tmp.ProductName;
 

 属性            大小     日期    时间   名称
----------- ---------  ---------- -----  ----

     文件       2965  2011-09-23 20:57  WCFDemo\AccessDB\AccessDB.csproj

     文件       7168  2011-09-23 22:11  WCFDemo\AccessDB\bin\Debug\AccessDB.dll

     文件      15872  2011-09-23 22:11  WCFDemo\AccessDB\bin\Debug\AccessDB.pdb

     文件      10240  2011-09-23 22:11  WCFDemo\AccessDB\bin\Debug\DBModel.dll

     文件      17920  2011-09-23 22:11  WCFDemo\AccessDB\bin\Debug\DBModel.pdb

     文件       3682  2011-09-23 22:11  WCFDemo\AccessDB\DBHelper.cs

     文件        956  2011-09-23 22:11  WCFDemo\AccessDB\obj\Debug\AccessDB.csproj.FileListAbsolute.txt

     文件       7168  2011-09-23 22:11  WCFDemo\AccessDB\obj\Debug\AccessDB.dll

     文件      15872  2011-09-23 22:11  WCFDemo\AccessDB\obj\Debug\AccessDB.pdb

     文件       3853  2011-09-23 22:11  WCFDemo\AccessDB\obj\Debug\ResolveAssemblyReference.cache

     文件       1348  2011-09-23 14:09  WCFDemo\AccessDB\Properties\AssemblyInfo.cs

     文件        484  2011-09-23 14:00  WCFDemo\DBModel\App.Config

     文件      10240  2011-09-23 22:11  WCFDemo\DBModel\bin\Debug\DBModel.dll

     文件        484  2011-09-23 14:00  WCFDemo\DBModel\bin\Debug\DBModel.dll.config

     文件      17920  2011-09-23 22:11  WCFDemo\DBModel\bin\Debug\DBModel.pdb

     文件       3362  2011-09-23 15:14  WCFDemo\DBModel\DBModel.csproj

     文件        179  2011-09-23 14:35  WCFDemo\DBModel\DesktopComputer.cs

     文件       7265  2011-09-23 14:00  WCFDemo\DBModel\EntityModel.Designer.cs

     文件       3905  2011-09-23 14:00  WCFDemo\DBModel\EntityModel.edmx

     文件        227  2011-09-23 14:49  WCFDemo\DBModel\NotebookComputer.cs

     文件        820  2011-09-23 22:11  WCFDemo\DBModel\obj\Debug\DBModel.csproj.FileListAbsolute.txt

     文件      10240  2011-09-23 22:11  WCFDemo\DBModel\obj\Debug\DBModel.dll

     文件      17920  2011-09-23 22:11  WCFDemo\DBModel\obj\Debug\DBModel.pdb

     文件       4608  2011-09-23 15:07  WCFDemo\DBModel\obj\Debug\Refactor\DBModel.dll

     文件       5632  2011-09-23 14:00  WCFDemo\DBModel\obj\Debug\TempPE\EntityModel.Designer.cs.dll

     文件       1889  2011-09-23 20:55  WCFDemo\DBModel\Products.cs

     文件       1346  2011-09-23 13:58  WCFDemo\DBModel\Properties\AssemblyInfo.cs

     文件       4890  2011-09-23 20:39  WCFDemo\Host\App.config

     文件       7168  2011-09-23 22:11  WCFDemo\Host\bin\Debug\AccessDB.dll

     文件      15872  2011-09-23 22:11  WCFDemo\Host\bin\Debug\AccessDB.pdb

............此处省略156个文件信息

评论

共有 条评论

相关资源