笔记:参数为引用类型是否需要使用ref关键字

 
 
结论:引用类型也必须使用ref关键字
提问:在 DeleteRepeat 中是直接对dsRepeat进行操作,为什么方法执行完毕之后dsRepeat没有变化?
测试代码:
   
   
if (erpc.UpLoadExcel(dt, ref iSuccess, ref iRepeat, ref iFailed, ref dsRepeat))
                {
                    Code.Comm.ExcelOpration excel = new Code.Comm.ExcelOpration();
                    if (iRepeat != 0)
                    {
                        excel.ExcelRootPath = @"~/uploads/CustomerTemp/";
			//不使用ref时dsRepeat为空,所以此处会报dsRepeat不包含Tables[0]的错误
                        excel.DataTabletoExcel(dsRepeat.Tables[0], "重复客户", new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "客户名称", Mapping = "name" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "联系人", Mapping = "contact" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "性别", Mapping = "sex" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "手机", Mapping = "cellpone" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "固定电话", Mapping = "telephone" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "邮箱", Mapping = "email" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "QQ", Mapping = "qq" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "省份", Mapping = "province" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "城市", Mapping = "city" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "联系地址", Mapping = "address" },
                                                                               new CallCenter.Web.Code.Comm.CustomeColumn() { ColumnName = "客户备注", Mapping = "notes" });
                    }

                    X.Msg.Alert("温馨提示", "成功导入数据<span style='color:red'>" + iSuccess + "</span>条,失败<span style='color:red'>" +
                                iFailed + "</span>条,重复<span style='color:red'>" + iRepeat + "</span>条" +
                                (iRepeat == 0 ? "" : "<br/><br/>点击下载重复数据==><a href='\\uploads\\CustomerTemp\\" + excel.ExcelFileName + ".xls'>" + excel.ExcelFileName + ".xls</a>")).Show();
                    grid_customer.Reload();
                }





public int DeleteRepeat(ref DataSet ds)
        {
            int rowCount = 0;
            string strIds;
            string strSql = "select * from erp_customer where id not in(select min(id) from erp_customer group by name,cellpone,email)";
            ds = DbHelperSQL.Query(strSql);
            if (ds.Tables.Count > 0)
            {
                strIds = "";
                rowCount = ds.Tables[0].Rows.Count;
                foreach (DataRow dr in ds.Tables[0].Rows)
                {
                    strIds += dr["id"].ToString() + ",";
                }
                if (strIds != "")
                {
                    strIds = strIds.Substring(0, strIds.Length - 1);
                    string strDel = "Delete from erp_customer where id in(" + strIds + ")";
                    rowCount = DbHelperSQL.ExecuteSql(strDel);
                }
            }
            return rowCount;
        }




   
   
public bool UpLoadExcel(DataTable dtExcel, ref int successCount, ref int repeatCount, ref int failedCount, ref DataSet dsRepeat)
        {
            int iCount = dtExcel.Rows.Count;
            successCount = 0;
            repeatCount = 0;
            failedCount = 0;
            List<String> listSqls = new List<string>();
            try
            {
                foreach (DataRow dr in dtExcel.Rows)
                {
                    StringBuilder sb = new StringBuilder();
                    sb.Append("insert into erp_customer(name,contact,sex,cellpone,telephone,email,qq,province,city,address,notes,creator,createtime,modifier,modifytime,activeflag,flag,ispublic,customertype)");
                    sb.Append("values('{0}','{1}','{2}','{3}','{4}','{5}','{6}','{7}','{8}','{9}','{10}',{11},'{12}',{13},'{14}',{15},{16},{17},{18})");
                    listSqls.Add(string.Format(sb.ToString(), dr["客户名称"],
                                                                dr["联系人"],
                                                                dr["性别"],
                                                                dr["手机"],
                                                                dr["固定电话"],
                                                                dr["邮箱"],
                                                                dr["QQ"],
                                                                dr["省份"],
                                                                dr["城市"],
                                                                dr["联系地址"],
                                                                dr["客户备注"],
                                                                dr["creator"],
                                                                dr["createtime"],
                                                                dr["modifier"],
                                                                dr["modifytime"],
                                                                dr["activeflag"],
                                                                dr["flag"],
                                                                dr["ispublic"],
                                                                dr["customertype"]));
                }

                successCount = DbHelperSQL.ExecuteSqlTran(listSqls);
                repeatCount = DeleteRepeat(ref dsRepeat);
                failedCount = iCount - successCount;
                successCount = iCount - repeatCount - failedCount;
                return true;
            }
            catch
            {
                return false;
            }
        }



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值