excel宏调用webservice使用存储过程同步excel数据的方法

excel宏:

随后更新


webservice:

1.创建空应用程序

2.添加web服务

3.创建数据库访问类库DataHelper


sqlserver:

创建数据同步的存储过程



以下是一些需要的代码,比较杂乱,有空再整理整理。

DataFactory.cs

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

namespace DataHelper
{
    public class DataFactory
    {
        /// <summary>
        /// 获取数据类型1为sqlserver,2为access
        /// </summary>
        /// <param name="type"></param>
        /// <returns></returns>
        public static DbHelper GetHelper()
        {
            string ConnStr = ConfigurationManager.AppSettings["ConnStr"].ToString();
            int Dbtype = 1;
            Int32.TryParse(ConfigurationManager.AppSettings["DbType"].ToString(), out Dbtype);
            switch (Dbtype)
            {
                case 1:
                    return new SqlHelper(ConnStr);
                case 2:
                    return new OledbHelper(ConnStr);
                default:
                    return new SqlHelper(ConnStr);
            }
        }

        public static DbHelper GetHelper1()
        {
            string ConnStr = ConfigurationManager.AppSettings["ConnStr1"].ToString();
            int Dbtype = 1;

            Int32.TryParse(ConfigurationManager.AppSettings["DbType"].ToString(), out Dbtype);
            switch (Dbtype)
            {
                case 1:
                    return new SqlHelper(ConnStr);
                case 2:
                    return new OledbHelper(ConnStr);
                default:
                    return new SqlHelper(ConnStr);
            }
        }



        public static DbHelper GetYellowPageHelper()
        {
            string ConnStr = ConfigurationManager.AppSettings["ConnStrYP"].ToString();
            int Dbtype = 1;

            Int32.TryParse(ConfigurationManager.AppSettings["DbType"].ToString(), out Dbtype);
            switch (Dbtype)
            {
                case 1:
                    return new SqlHelper(ConnStr);
                case 2:
                    return new OledbHelper(ConnStr);
                default:
                    return new SqlHelper(ConnStr);
            }
        }


        /// <summary>
        /// Discuz数据库
        /// </summary>
        /// <returns></returns>
        public static DbHelper GetYellowPageHelperDNT()
        {
            string ConnStr = ConfigurationManager.AppSettings["ConnStrDNT"].ToString();
            int Dbtype = 1;

            Int32.TryParse(ConfigurationManager.AppSettings["DbType"].ToString(), out Dbtype);
            switch (Dbtype)
            {
                case 1:
                    return new SqlHelper(ConnStr);
                case 2:
                    return new OledbHelper(ConnStr);
                default:
                    return new SqlHelper(ConnStr);
            }
        }
    }
}


DbHelper.cs

using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Collections.Specialized;

namespace DataHelper
{
    public abstract class DbHelper
    {
        /// <summary>
        /// 得到数据库链接
        /// </summary>
        public abstract IDbConnection Connection { get; }
        /// <summary>
        /// 打开数据库连接;  
        /// </summary>
        public abstract void Open();
        /// <summary>
        /// 关闭数据库链接;
        /// </summary>
        public abstract void Close();
        /// <summary>
        /// 开始一个事务;
        /// </summary>
        public abstract void BeginTrans();
        /// <summary>
        /// 提交一个事务;
        /// </summary>
        public abstract void CommitTrans();
        /// <summary>
        /// 回滚一个事务;
        /// </summary>
        public abstract void RollBackTrans();
        /// <summary>
        /// 执行sql语句,返回受影响集合数
        /// </summary>
        /// <param name="cmdType">命令类型</param>
        /// <param name="cmdText">命令字符串</param>
        /// <param name="commandParameters">命令参数</param>
        /// <returns></returns>

  • 2
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值