C_Sharp 板


LINE

说明一下 我的原始资料是以 xml 存在於 table_content 里的 column 里,栏位名称 content 为了要搜寻资料,我用 xml 将 content 里的资料,用解析的方式写成 view 但因为 view 的速度实在太慢,为了改善效能,每天晚上排程将 view 转成 table 部份程式 tbCmd = new SqlCommand(); // 到 table 取值 vwCmd = new SqlCommand(); // 到 view 取值 Cmd = new SqlCommand(); List<string> vwCond = new List<string>(); List<string> tbCond = new List<string>(); List<string> Cond = new List<string>(); DataTable mainDt = new DataTable(); DataTable vwDt = new DataTable(); //开始指定共用的 sql 条件 if (txtVndrNm.Text != "") { Cond.Add("VENDOR_NAME LIKE '%' + @vendorNm + '%'"); Cmd.Parameters.Add("@vendorNm", SqlDbType.VarChar).Value = txtVndrNm.Text.Trim(); } // 把共用的 command text 分别复制给变数 vwCmd = Cmd; tbCmd = Cmd; // 把共用的 condition 分别复制给变数 vwCond = Cond; tbCond = Cond; //最後组装 //view 的部份限定只搜寻符合今天日期的资料 -> 效能考量 vwCond.Add("BEGIN_TIME>=@vwbgTimeStart"); vwCmd.Parameters.Add("@vwbgTimeStart", SqlDbType.VarChar).Value = today + " 00:00"; vwCond.Add("BEGIN_TIME<=@vwbgTimeEnd"); vwCmd.Parameters.Add("@vwbgTimeEnd", SqlDbType.VarChar).Value = today + " 23:59"; vwCmd.CommandText = bindContition(todaySql, vwCond); tbCmd.CommandText = bindContition(oldSql, tbCond); 问题来了 在最後组装的时候,我将 "限定资料范围=今天" 的条件指派到 vwCond 但不知为何 tbCond 同样收到了... 囧rz vwCond = Count = 3 tbCond = Count = 3 内容是一样的 0 = "VENDOR_NAME LIKE '%' + @vendorNm + '%'" 1 = "BEGIN_TIME>=@vwbgTimeStart" 2 = "BEGIN_TIME<=@vwbgTimeEnd" tbCond 应该只有 count = 1 ,而且内容只有上面的 vendor_name 不知道哪里出了问题 我 google 过传值呼叫和传址呼叫,但和我的问题好像没有关系 .. --



※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.132.93.23
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/C_Sharp/M.1474120561.A.AF1.html
1F:推 soup514: value type vs reference type 09/17 22:23
意思是 vwCond 和 tbCond 都被我宣告成 reference type 吗? 但我看文件是说必须用 ref 才能宣告成 reference type ... = =a 是我误解了吗? 後来用这个方法处理 vwCmd = tbCmd = Cmd; List<string> vwCond = new List<string>(Cond); List<string> tbCond = new List<string>(Cond); 我知道应该是我的宣告是变成 reference type , 变数2 = 变数1 变数3 = 变数1 刚 google 到大概可以做出这样的结论 想知道有没比较好的做法 m(_ _)m ※ 编辑: aeolus0829 (220.132.93.23), 09/17/2016 23:06:49
2F:推 CrazyAngel: 泛型就是参考型别。也可以用AddRange把相同条件加进去 09/18 00:24
啊.. 这个方法昨天看到的网页好像也有提到 http://iblog.16806.com/?p=119
3F:→ Litfal: 把建立Command的方法拉到另一个函数去做 09/18 01:19
目前这个函数是判断使用者有没有输入条件 有就丢到 list 里 检察完会再呼叫另一个函数将 list 组装成 command text 我想你应该是这个意思? ※ 编辑: aeolus0829 (220.132.93.23), 09/18/2016 11:13:28







like.gif 您可能会有兴趣的文章
icon.png[问题/行为] 猫晚上进房间会不会有憋尿问题
icon.pngRe: [闲聊] 选了错误的女孩成为魔法少女 XDDDDDDDDDD
icon.png[正妹] 瑞典 一张
icon.png[心得] EMS高领长版毛衣.墨小楼MC1002
icon.png[分享] 丹龙隔热纸GE55+33+22
icon.png[问题] 清洗洗衣机
icon.png[寻物] 窗台下的空间
icon.png[闲聊] 双极の女神1 木魔爵
icon.png[售车] 新竹 1997 march 1297cc 白色 四门
icon.png[讨论] 能从照片感受到摄影者心情吗
icon.png[狂贺] 贺贺贺贺 贺!岛村卯月!总选举NO.1
icon.png[难过] 羡慕白皮肤的女生
icon.png阅读文章
icon.png[黑特]
icon.png[问题] SBK S1安装於安全帽位置
icon.png[分享] 旧woo100绝版开箱!!
icon.pngRe: [无言] 关於小包卫生纸
icon.png[开箱] E5-2683V3 RX480Strix 快睿C1 简单测试
icon.png[心得] 苍の海贼龙 地狱 执行者16PT
icon.png[售车] 1999年Virage iO 1.8EXi
icon.png[心得] 挑战33 LV10 狮子座pt solo
icon.png[闲聊] 手把手教你不被桶之新手主购教学
icon.png[分享] Civic Type R 量产版官方照无预警流出
icon.png[售车] Golf 4 2.0 银色 自排
icon.png[出售] Graco提篮汽座(有底座)2000元诚可议
icon.png[问题] 请问补牙材质掉了还能再补吗?(台中半年内
icon.png[问题] 44th 单曲 生写竟然都给重复的啊啊!
icon.png[心得] 华南红卡/icash 核卡
icon.png[问题] 拔牙矫正这样正常吗
icon.png[赠送] 老莫高业 初业 102年版
icon.png[情报] 三大行动支付 本季掀战火
icon.png[宝宝] 博客来Amos水蜡笔5/1特价五折
icon.pngRe: [心得] 新鲜人一些面试分享
icon.png[心得] 苍の海贼龙 地狱 麒麟25PT
icon.pngRe: [闲聊] (君の名は。雷慎入) 君名二创漫画翻译
icon.pngRe: [闲聊] OGN中场影片:失踪人口局 (英文字幕)
icon.png[问题] 台湾大哥大4G讯号差
icon.png[出售] [全国]全新千寻侘草LED灯, 水草

请输入看板名称,例如:Soft_Job站内搜寻

TOP