2013年12月24日 星期二

[除錯] 無法繫結至 DataSource 上的屬性或欄位 或 無法清除這個清單

原因:
Error:無法繫結至 DataSource 上的屬性或欄位
            bs_tblT內外銷統計附檔.DataMember = null;
            bs_tblT內外銷統計附檔.DataSource = null;

Error:無法清除這個清單
            bs_tblT內外銷統計附檔.Clear();

解決:
用bindingsource isbindingsuspended


            foreach (Control item in this.tableLayoutPanel1.Controls)
            {
                item.DataBindings.Clear();
            }
            lbl_檔案名稱.DataBindings.Clear();  
            //忘記把這個ctl給DataBindings.Clear()...
            //因為此ctl是屬於flowLayoutPanel2
            //而flowLayoutPanel2是屬於tableLayoutPanel1
            //所以此ctl我需要另外將其DataBindings.Clear()
            //而不是寫在foreach裡面...那邊只會找到flowLayoutPanel2

參考:
我的表單本來可以開啟的,因為我把access資料庫裡的欄位user改成user_1
[除錯] System.InvalidCastException: System.Data.DataViewManagerListItemTypeDescriptor
如何在dataTable更新完成後,才讓綁定的dataGridView 做更新?

2013年12月13日 星期五

[除錯] entilb DAAB [The type Database cannot be constructed. You must configure the container to supply this value]

 問題:
The type Database cannot be constructed. You must configure the container to supply this value.

Activation error occured while trying to get instance of type Database, key "ExpSys.Properties.Settings.ConnSqlStr"

解決:
組件[YC_ExpSys.exe]
設定檔[YC_ExpSys.exe.config]

當組件在組件[DayCensorWinApp.exe]上運行時
設定檔[DayCensorWinApp.exe.config]需新增設定檔[YC_ExpSys.exe.config]的設定資料
因為是由[DayCensorWinApp.exe]開啟[YC_ExpSys.exe]
而其設定檔是讀[DayCensorWinApp.exe.config]

環境:
entlib 5.0
vs2010
.net 3.5 sp1

參考:
The type Database cannot be constructed. You must configure the container to supply this value.
The type Database cannot be constructed. You must configure the container to supply this value (EntLib 5 + ODP.NET)
Activation error occured while trying to get instance of type Database, key "cnx"
Activation error occured while trying to get instance of type Database, key “” <— blank
Enterprise Library 5 with ODP.NET

2013年12月12日 星期四

[SQL] 去除欄位中(或左右兩邊)的空白

Q:
在SELECT COUNT(*)時都無法正確取得數量...
故猜測是多了空白...

A:
某A在插入CustomerOrderNo時, 右邊多了N個空白...

Solution Code:
SELECT a.CustomerOrderNo,a.CustomerOrderDate,a.CustomerID,a.CompanyName,(SELECT count(*) FROM [tblT出貨統計資料表] WHERE CustomerOrderNo = replace(a.CustomerOrderNo,' ','')) as Qty
FROM [tblT訂單統計資料表] as a LEFT JOIN [tblODeliveryOrder] as b on a.CustomerOrderNo = b.CustomerOrderNo WHERE b.DeliveryOrderNo = 'PO201210030';

參考:
去除MS SQL欄位中空白
sql字串去除左右空白字元
SQL Trim 函數

2013年11月14日 星期四

[除錯] 因為程式無法認可或結束儲存格值的變更

情況:
承自 DataGridView 的擴展控項 myDataGridView
當CellValidating...沒過...Coding為e.cancel=true;
則程式最先進入控項的ProcessDialogKey...
當Cdoing為base.CurrentCell = base.Rows[base.CurrentCell.RowIndex].Cells[nextColumn.Index];
便會出現錯誤訊息「因為程式無法認可或結束儲存格值的變更」
所以要改寫以下...(紅色+判斷)
        protected override bool ProcessDialogKey(System.Windows.Forms.Keys keyData)
        {
            //MessageBox.Show(this.CurrentCell.RowIndex.ToString());
            if (keyData == Keys.Tab || keyData == Keys.Enter)
            {
                if ((base.CurrentCell == null))
                {
                    return true;
                }
                DataGridViewColumn nextColumn = null;
                nextColumn = base.Columns.GetNextColumn(base.Columns[base.CurrentCell.ColumnIndex], DataGridViewElementStates.Visible, DataGridViewElementStates.ReadOnly);
                if ((nextColumn != null))
                {
                    if(this.CurrentCell.IsInEditMode)
                        //當驗證沒過時, Coding部份為e.cancel=true, 使用這個方式就不會出錯了!
                        return base.ProcessDialogKey(Keys.Tab); 
                    else
                        base.CurrentCell = base.Rows[base.CurrentCell.RowIndex].Cells[nextColumn.Index];

                }
                else
                {
                    nextColumn = base.Columns.GetFirstColumn(DataGridViewElementStates.Visible, DataGridViewElementStates.ReadOnly);
                    if ((base.CurrentCell.RowIndex + 1) == base.Rows.Count)
                    {
                        base.CurrentCell = base.Rows[0].Cells[nextColumn.Index];
                    }
                    else
                    {
                        if (this.CurrentCell.IsInEditMode)
                            //當驗證沒過時, Coding部份為e.cancel=true, 使用這個方式就不會出錯了!
                            return base.ProcessDialogKey(Keys.Tab); 
                        else
                            base.CurrentCell = base.Rows[base.CurrentCell.RowIndex + 1].Cells[nextColumn.Index];
                    }
                }
                //MessageBox.Show(this.CurrentCell.RowIndex.ToString());
                return true;
            }
            return base.ProcessDialogKey(keyData);
        }

參考:
[C#]DataGridView欄位驗證只能是數字且不能為空白
DataGridView.Rows.Clear() raise exception 
You received exception message Exception.InvalidOperation "Operation did not succeed because the program cannot commit or quit a cell value change." . If this DataGridView cell is in edit mode, you have to end/submit edit and then continue.

DataGridView 控制項 (Windows Form)

2013年10月7日 星期一

[SQL] SQL SERVER 如何區分大小寫?

String[] SqlQry = new String[1];
SqlQry[0] = "SELECT * FROM [A000幣別] WHERE 幣別編號 like @幣別編號 Collate Chinese_Taiwan_Stroke_CS_AS;";

DictionaryEntry[] SqlParas = new DictionaryEntry[1];
SqlParas[0].Key = "幣別編號";
SqlParas[0].Value = "%E%";

參考:
SQL SERVER 如何區分大小寫?
[SQL SERVER][Memo]如何設定Column區分大小寫

2013年9月28日 星期六

[學習] 在HashTable容器上做Object的存取...

說明:
當cmb事件觸發時, 根據cmb.SelectedValue做為HashTable的Key
並取出對應Key的Value值...
而Value為一個類別(cls_marking)...

C#:
[cls_marking.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ExportSys
{
    class cls_marking
    {
        private bool _disposed = false;

        private String _mk1;
        private String _mk2;
        private String _mk3;
        private String _mk4;
        private String _mk5;
        private String _mk6;
        private String _mk7;
        private String _mk8;
        private String _mk9;

        //建構子
        //public cls_marking(String g,String b);

        public cls_marking(String mk1, String mk2,
            String mk3, String mk4,
            String mk5, String mk6,
            String mk7, String mk8, String mk9)
        {
            this._mk1 = mk1;
            this._mk2 = mk2;
            this._mk3 = mk3;
            this._mk4 = mk4;
            this._mk5 = mk5;
            this._mk6 = mk6;
            this._mk7 = mk7;
            this._mk8 = mk8;
            this._mk9 = mk9;
            this._disposed = false;
        }

        public override string ToString()
        {
            return _mk1 + " " + _mk2 + " " + _mk3 + " " + _mk4 + " " + _mk5 + " " + _mk6 + " " + _mk7 + " " + _mk8 + " " + _mk9;
        }

        public string mk1
        {
            get { return _mk1; }
            set { _mk1 = value; }
        }

        public string mk2
        {
            get { return _mk2; }
            set { _mk2 = value; }
        }

        public string mk3
        {
            get { return _mk3; }
            set { _mk3 = value; }
        }

        public string mk4
        {
            get { return _mk4; }
            set { _mk4 = value; }
        }

        public string mk5
        {
            get { return _mk5; }
            set { _mk5 = value; }
        }

        public string mk6
        {
            get { return _mk6; }
            set { _mk6 = value; }
        }

        public string mk7
        {
            get { return _mk7; }
            set { _mk7 = value; }
        }

        public string mk8
        {
            get { return _mk8; }
            set { _mk8 = value; }
        }

        public string mk9
        {
            get { return _mk9; }
            set { _mk9 = value; }
        }

        public void Dispose()
        {
            Dispose(true);

            // Use SupressFinalize in case a subclass
            // of this type implements a finalizer.
            GC.SuppressFinalize(this);
        }

        protected virtual void Dispose(bool disposing)
        {
            // If you need thread safety, use a lock around these
            // operations, as well as in your methods that use the resource.
            if (!_disposed)
            {
                if (disposing)
                {
                    if (_mk1 != null)
                    {
                        _mk1 = null;
                        _mk2 = null;
                        _mk3 = null;
                        _mk4 = null;
                        _mk5 = null;
                        _mk6 = null;
                        _mk7 = null;
                        _mk8 = null;
                        _mk9 = null;
                    }
                    Console.WriteLine("Object disposed.");
                }

                // Indicate that the instance has been disposed.
                _mk1 = null;
                _mk2 = null;
                _mk3 = null;
                _mk4 = null;
                _mk5 = null;
                _mk6 = null;
                _mk7 = null;
                _mk8 = null;
                _mk9 = null;
                _disposed = true;
            }
        }
    }
}

[ExpOrder.cs]
private Hashtable htb_mark = new Hashtable();

private void cmdBing()
{
       cmb_印字編號.DisplayMember = "Value";
       cmb_印字編號.ValueMember = "Key";
       ArrayList al = new ArrayList();
       using (IDataReader reader = db.ExecuteReader(db.GetSqlStringCommand("SELECT MARK代碼 + '(' + 中文名稱 + ')' as 中文名稱,MARK代碼,MARK1,MARK2,MARK3,MARK4,MARK5,MARK6,MARK7,MARK8,MARK9 FROM [tbl資料表];")))
       {
              if (htb_mark.Count > 0) htb_mark.Clear();
              while (reader.Read())
              {
                        al.Add(new DictionaryEntry(reader.GetValue(1), reader.GetValue(0)));

                        cls_marking mark = new cls_marking(reader["MARK1"].ToString(), reader["MARK2"].ToString(),
                            reader["MARK3"].ToString(), reader["MARK4"].ToString(), reader["MARK5"].ToString(), 
                            reader["MARK6"].ToString(), reader["MARK7"].ToString(), reader["MARK8"].ToString(), 
                            reader["MARK9"].ToString());
                        
                        htb_mark.Add(reader["MARK代碼"].ToString(), mark);
               }
                    cmb_印字編號.DataSource = al;
        }
}

private void cmb_印字編號_SelectedIndexChanged(object sender, EventArgs e)
{
     this.txt_印字1.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk1.ToString();
     this.txt_印字2.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk2.ToString();
     this.txt_印字3.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk3.ToString();
     this.txt_印字4.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk4.ToString();
     this.txt_印字5.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk5.ToString();
     this.txt_印字6.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk6.ToString();
     this.txt_印字7.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk7.ToString();
     this.txt_印字8.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk8.ToString();
     this.txt_印字9.Text = ((cls_marking)htb_mark[cmb_印字編號.SelectedValue]).mk9.ToString();
}

private void btn_Test(object sender, EventArgs e)
{
     //法一
     foreach(DictionaryEntry item in htb_mark)
     {
          MessageBox.Show(item.Key + " = " + ((cls_marking)item.Value).mk1);
     }

     //法二
     foreach(cls_marking item in htb_mark.Values)
     {
          MessageBox.Show(item.mk1.ToString());
      }

//法三
//variable to hold the list of songs
string list = string.Empty;
//create an instance of the IDictionaryEnumerator Interface
IDictionaryEnumerator enumerator;
//make sure our Hashtable holds items
if (htb_mark.Count > 0)
{
     //let the user know what we're doing
     MessageBox.Show("The following songs are in your list:");      
     //now set out IDictionaryEnumerator value
     enumerator = htb_mark.GetEnumerator();      
     //now use the MoveNext Method to iterate through our list
     while (enumerator.MoveNext())
     {
          //keep adding song names until we reach the end
          list += enumerator.Value.ToString() + "\r\n";
     }
     //now show the song names
     MessageBox.Show(list);
}

}

缺點:
C# - 替代 Hashtable 沒有泛型的方案
雖然Hashtable在某些地方很好用,但在某些情況下,反而成了礙手礙腳的。
Hashtable裡面的物件都是存成object,倘若要不斷的使用物件,就要不斷的轉型…
一來折損不少效能,二來程式碼看起來就很不舒服

其實,解決方法有很多種,只是找不到有詳盡介紹 C# 所有Collections的好文章。
最根本的做法就是直接去實作Collections使用的介面,但是又整個很麻煩的感覺。
一直在想,都有List<>的泛型了,為啥沒有對應
Hashtable的泛型咧~
今天終於給我咕到一個好用的Collections可以取代之!

參考:
DictionaryEntry 結構
C#集合--Dictionary

Hashtable 類別
C#中HashTable的用法
C#中如何操作HashTable类呢?
Hashtablekey, value键值对均为object类型,所以Hashtable以支持任何类型的keyvalue键值对.

C#集合之Hashtable
C# 應用雜湊表(Hashtable)
什麼是 Dictionaries
Using The C# Hashtable Collection
C# Hashtable
C#: Storing Instance of Objects in (Hashtable)

How to Serialize a Dictionary or Hashtable in C#

使用泛型類別解決 ComboBox 的自訂資料繫結問題

集合與泛型對應
c#中Dictionary、ArrayList、Hashtable和数组 Array 的区别
Array和ArrayList的异同点

2013年9月27日 星期五

[學習] 藉由 ArrayList 裝載 DataReader 數據,並做為 ComboBox 數據來源...

說明:
一般來講都是透過DataTable來做為ComboBox的數據來源…
來設置 DisplayMember 與 ValueMember

選用 DataSet 或 DataReader
DataReader和Dataset的性能比较
但似乎DataTable讀取效率較沒有DataReader快...
在WebForm, ComBoBox可直接DataReader當數據, WinForm 則否...
WinForm [error msg] 複雜 DataBinding 接受以 IList 或 IListSource 做為資料來源。
故可考慮下面方式...
當數據非常多筆(數千, 數萬)時, 此方法與DataTable的效率比較,尚待測試...

C#:[WinForm]
using System.Collections;

cmb_印字編號.DisplayMember = "Value";
cmb_印字編號.ValueMember = "Key";
ArrayList al = new ArrayList();
using (IDataReader reader = db.ExecuteReader(db.GetSqlStringCommand("SELECT MARK代碼 + '(' + 中文名稱 + ')' as 中文名稱,MARK代碼 FROM [tb資料表];")))
{
     while (reader.Read())
     {
          al.Add(new DictionaryEntry(reader.GetValue(1), reader.GetValue(0)));
     }
     cmb_印字編號.DataSource = al;
}

備註:
关于.net winform ComboBox的DataSource,DisplayMember和ValueMember属性的设置顺序的问题。
ComboBox配置数据源需要注意的一个问题
.NET各大平台数据列表控件绑定原理及比较(WebForm、Winform、WPF)

參考:
ArrayList 類別
winform下comboBox控件绑定数据并设置其value【整理】
winform中combox的运用

其它參考:List / IList / IListSource
IList 介面
IListSource 介面
How do i bind data source to a ComboBox?
how to bind a list to a combobox? (Winforms)
Populating a ComboBox using C#
C# - 使用 LIST 為 COMBOBOX 加入 ITEM
Complex DataBinding accepts as a data source either an IList or an IListSource.
WinForm控件复杂数据绑定常用数据源(对Combobox,DataGridView等控件DataSource赋值的多种方法)
C# IList, ArrayList与List的区别详解 & 简单用法举例(转)
Array和ArrayList的异同点
VB.NET的Array VS ArrayList
c#中Dictionary、ArrayList、Hashtable和数组 Array 的区别
C#集合--Dictionary

How to return datareader from a web service?

2013年9月22日 星期日

[除錯] Entlib 5.0 DAAB 因相依性問題,而無法解析組件。

當在使用DAAB (Data Access Application Block) 時, compile 出現Error :
無法解析所參考的組件 "Microsoft.Practices.EnterpriseLibrary.Data.SqlCe, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL",因為它在 "System.Data.OracleClient, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" 上有相依性,而後者不在目前的目標 Framework ".NETFramework,Version=v4.0,Profile=Client" 中。請移除不在目標 Framework 中的組件參考,或考慮重新設定專案的目標。

解法:
修改專案[屬性][目標 Framework] 從.Net Framework 4 Client profile , 改成.Net Framework

環境:
VS2010 C#.Net
Entlib 5.0, DAAB

參考:
Enterprise Library 5.0, A dependency on System.Data.OracleClient


2013年8月27日 星期二

[SQL] 不足位數補上零 "0" & 編碼方式[NG-年度-流水號] & 編碼方式[CS年度月份流水號]

編碼方式:
NG-年度-流水號

範例一:
假設目前編號最大號 NG-13-037

SQL:找出最大值+1
SELECT top 1 left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) 報表編號 FROM [瑕疵異狀表] WHERE 報表編號 like 'NG-' + Right(year(GetDate()),2) + '-%'  ORDER BY 報表編號 DESC;

insert into [瑕疵異狀表] (報表編號) SELECT top 1 left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) 報表編號 FROM [瑕疵異狀表] WHERE 報表編號 like 'NG-' + Right(year(GetDate()),2) + '-%'  ORDER BY 報表編號 DESC;

結果:
NG-13-038

範例二:
假設今年為 2014 而最大號為 NG-13-038
若是要產生今年的第一筆 NG-14-001 
接續產生今年(2014)第二筆 NG-14-002 
第N筆 NG-14-N...

SQL:承一更改如下
select top 1 case when convert(nvarchar(10),(select count(報表編號) from [瑕疵異狀表] where substring(報表編號,4,2)=right(year(getdate()),2))) = '0' then 'NG-' + right(year(getdate()),2) + '-001' else  left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) end 報表編號 from [瑕疵異狀表] order by  substring(報表編號,4,2) desc,right(報表編號,3) desc; --where 報表編號 like 'NG-' + Right(year(GetDate()),2) + '-%'  ORDER BY 報表編號 DESC;

insert into [瑕疵異狀表] (報表編號) select top 1 case when convert(nvarchar(10),(select count(報表編號) from [瑕疵異狀表] where substring(報表編號,4,2)=right(year(getdate()),2))) = '0' then 'NG-' + right(year(getdate()),2) + '-001' else  left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) end 報表編號 from [瑕疵異狀表] order by  substring(報表編號,4,2) desc,right(報表編號,3) desc; --where 報表編號 like 'NG-' + Right(year(GetDate()),2) + '-%'  ORDER BY 報表編號 DESC;

結果:
NG-14-001

範例三:承二
當資料有 NG-13-001 ~ n, NG-15-001 ~ n...
藍色因條件在, 
調整日期 2013年, 則無法產生 NG-13-(n+1), 而是產出 NG-15-(n+1)
調整日期 2014年, 則正常產生 NG-14-001
調整日期 2016年, 則正常產生 NG-16-001

當資料有 NG-13-001 ~ n, NG-15-001 ~ n...
綠色因條件在, 
調整日期 2013年, 則正常產生 NG-13-(n+1)
調整日期 2014年, 則無法產生 NG-14-001
調整日期 2016年, 則無法產生 NG-16-001

當資料有 NG-13-001 ~ n, NG-14-001 ~ n, NG-15-001 ~ n)
藍色因條件在, 
調整日期 2013年, 則無法產生 NG-13-(n+1), 而是產出 NG-15-(n+1)
調整日期 2014年, 則無法產生 NG-14-(n+1), 而是產出 NG-15-(n+1)
調整日期 2016年, 則正常產生 NG-16-001

當資料有 NG-13-001 ~ n, NG-15-001 ~ n...
綠色因條件在, 
調整日期 2013年, 則正常產生 NG-13-(n+1)
調整日期 2014年, 則正常產生 NG-14-(n+1)
調整日期 2016年, 則無法產生 NG-16-001

SQL:承二更改如下
select top 1 case when convert(nvarchar(10),(select count(報表編號) from [瑕疵異狀表] where substring(報表編號,4,2)=right(year(getdate()),2))) = '0' then 'NG-' + right(year(getdate()),2) + '-001' else   left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) end 報表編號 from [瑕疵異狀表] where substring(報表編號,4,2) <= right(year(getdate()),2)  order by  substring(報表編號,4,2) desc,right(報表編號,3) desc;

insert into [瑕疵異狀表] (報表編號) select top 1 case when convert(nvarchar(10),(select count(報表編號) from [瑕疵異狀表] where substring(報表編號,4,2)=right(year(getdate()),2))) = '0' then 'NG-' + right(year(getdate()),2) + '-001' else   left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) end 報表編號 from [瑕疵異狀表] where substring(報表編號,4,2) <= right(year(getdate()),2)  order by  substring(報表編號,4,2) desc,right(報表編號,3) desc;

試試資料依然正確...
NG-13-001 ~ n, NG-15-001 ~ n, NG-17-001 ~ n (無14年及16年的資料)

﹝另一解﹞ CS150210 + 1 = CS150211
:::資料最大值 CS150210 故取出時後二位數+1 = CS150211
:::若該年份該月份無資料列,則CS該年該月001

select top 1 case when (select count(文號) from [DayCsycDB].[dbo].[公文基本資料表]
where 文號 like 'CS'+right(100+year(getdate()),2)+right(100+month(getdate()),2)+'%') =0 then
'CS'+right(100+year(getdate()),2)+right(100+month(getdate()),2)+'01'
else left(文號,6)+convert(nvarchar(2),(right(文號,2)+1)) end 文號
 from [DayCsycDB].[dbo].[公文基本資料表]
where 文號 like 'CS'+right(100+year(getdate()),2)+right(100+month(getdate()),2)+'%'  ORDER BY Right(文號,2) DESC;

參考:
--select Right(100+month(GetDate()),2)
--select datepart(yyyy,getdate())
--select Right(year(GetDate()),2)
--select REPLICATE('0',4-LEN(substring('123',2,2)))+substring('123',2,2)
--select replicate('0',2)+convert(nvarchar(1),substring('123',3,1)+1)

--select  報表編號 from [瑕疵異狀表] where 報表編號 like '__-' + right(year(getdate()),2) + '-___' order by right(報表編號,3) desc;

--SELECT top 1 報表編號,count(報表編號) FROM [瑕疵異狀表] WHERE 報表編號 like 'NG-' + Right(year(GetDate()),2) + '-%' group by  報表編號 order by 報表編號 desc;

--SELECT top 1 left(報表編號,6) + replicate('0',3-len(substring(報表編號,7,3)+1))+convert(nvarchar(3),substring(報表編號,7,3)+1) 報表編號 FROM [瑕疵異狀表] WHERE 報表編號 like 'NG-' + Right(year(GetDate()),2) + '-%'  ORDER BY 報表編號 DESC;

--select 'CS' + right(right(12303+101,2),2)

--SELECT CASE WHEN MAX(財產電腦單號) IS NULL 
THEN 'FA' + right(year(getdate())-1911,3) + RIGHT(REPLICATE('0', 2) + CAST(month(getdate()) as NVARCHAR), 2) + '001' 
ELSE 'FA' + right(year(getdate())-1911,3) + RIGHT(REPLICATE('0', 2) + CAST(month(getdate()) as NVARCHAR), 2) + replicate('0',3-len(substring(MAX(財產電腦單號),8,3)+1)) + convert(nvarchar(3),substring(MAX(財產電腦單號),8,3)+1)  END 
FROM C000財產基本資料表Tmp 
--WHERE substring(財產電腦單號,3,5) <= right(year(getdate())-1911,3) + RIGHT(REPLICATE('0', 2) + CAST(month(getdate()) as NVARCHAR), 2)


--SELECT CASE WHEN MAX(財產電腦單號) IS NULL 
THEN 'FA' + right(year(getdate())-1911,3) + RIGHT(REPLICATE('0', 2) + CAST(month(getdate()) as NVARCHAR), 2) + '001' 
ELSE 'FA' + right(year(getdate())-1911,3) + RIGHT(REPLICATE('0', 2) + CAST(month(getdate()) as NVARCHAR), 2) + replicate('0',3-len(substring(MAX(財產電腦單號),8,3)+1)) + convert(nvarchar(3),substring(MAX(財產電腦單號),8,3)+1)  END 
FROM C000財產基本資料表 
WHERE substring(財產電腦單號,3,5) <= right(year(getdate())-1911,3) + RIGHT(REPLICATE('0', 2) + CAST(month(getdate()) as NVARCHAR), 2)



[VB.NET] String Format 格式化, 自動補零, 不足位元補零...
Mssql的字符字段如何按位数补零
SQL 字串補0
PLSQL & T-SQL - 字串不足數補零
將不足的位數補零
MS SQL 位數不足補0範例
[Google 搜尋] mssql 位數 補零
SQL函數 查詢SQL資料欄位相符的字串
MSSql 中Charindex ,Substring的使用
CHARINDEX (Transact-SQL)

[MSSQL]取得兩位數的月份或日期
--月
Select Right(100+Month(GetDate()),2)
--日
Select Right(100+Day(GetDate()),2)

Return a value if no rows are found SQL
Return a default value if no rows found
How to Assign a Default Value if No Rows Returned from the Select Query
Getting SELECT to return a constant value even if zero rows match

2013年8月22日 星期四

[學習] 利用ProcessStartInfo來列印

參考:
ProcessStartInfo 類別
ProcessStartInfo.Arguments 屬性
Sending byte array to printer
使用 C# 批次列印 PDF 檔案
[C#]使用預設印表機列印pdf文件
Try below code
Warning[] warnings;
      string  mimeType;
      string encoding;
      string extension;
      string deviceInfo;
      string[] streamids;
      deviceInfo =
       "<DeviceInfo>" +
       " <OutputFormat>PDF</OutputFormat>" +
       " <PageSize>A4</PageSize>" +
       " <PageWidth>8.5in</PageWidth>" +
       " <PageHeight>11in</PageHeight>" +
       " <MarginTop>0.25in</MarginTop>" +
       " <MarginLeft>0.25in</MarginLeft>" +
       " <MarginRight>0.25in</MarginRight>" +
       " <MarginBottom>0.25in</MarginBottom>" +
       "</DeviceInfo>";
      byte[] bytes  = ReportViewer1.ServerReport.Render("PDF", null, out mimeType, out encoding, out extension, out streamids, out warnings);  

FileStream fs = new FileStream(@"c:\output.PDF", 
        FileMode.Create);
      fs.Write(bytes, 0, bytes.Length);
      fs.Close();


ProcessStartInfo startInfo = new ProcessStartInfo();
      startInfo.UseShellExecute = true;
      startInfo.Verb = "Print";
      startInfo.Arguments = "Printer Name";
      startInfo.CreateNoWindow = false;
      startInfo.WindowStyle = ProcessWindowStyle.Hidden;
      startInfo.FileName = @"C:\output.pdf";
      Process p = new Process();
      p.StartInfo = startInfo;
      p.Start();

其它參考:

[學習] 利用Adobe來列印PDF

參考:
Print Pdf in C#
Printing a PDF from a .NET Service [closed]
PDF: direct printing with .NET
Printing ReportViewer direct to printer programatically
VB.Net Printing of PDFs

其它參考:

2013年8月21日 星期三

[學習] RDLC原生導出Excel之功能, 發生「忽略資料表/矩陣資料格中的子報表」

問題:
Subreports within table/matrix cells are ignored.
忽略資料表/矩陣資料格中的子報表

ReportViewer導出EXCEL時:(PDF則不會...)


解決:(就是不要把子報表放入Table或Matrix裡)
I created a List, placed the main table from the primary report in the list.
Below the table, but inside the List I placed the subreport.
Because the subreport is not inside the table, it will render in Excel.
RDLC原本設計
紅框:List
綠框:Table
黃框:SubReport

RDLC解決設計
最外框:List
紅框:Table1
楬框:SubReport
黃框:Table2
需要注意Table1底線(Bottom)與SubReport頂線(Top)不可重疊
同上SupReport的底線(Bottom)與Table2的頂線(Top)不可重疊

解決後導出EXCEL的結果:
(若導出PDF, 則當sub-report沒資料時, tb1與tb2之間的sub-report會消失,
故會畫二條的黑線[tb1的bottomBorderLine+tb2的topBorderLine], 比原本圖示的黑線約2倍,
這是因為tb1與subReport的距離隔0.001+SubRerpot與tb2的距離隔0.001)
若有發生如上之問題, 則把距離隔弄小就不會了!


不管用LIST/矩形,呈現上還是有缺陷
報表最佳呈現解法:先將資料預先處理好,在丟進到報表

參考:(用LIST or 矩形...)
VS2008
RDLC 9.0.0.0
如何在ReportingService報表樣板檔中嵌入子報表,卻又能匯出成Excel?
Reporting Services子報表導出EXCEL問題
rdlc 报表 矩阵 详解 分组、总计、表头、显示方向、序号
rdlc导出Excel时 显示"忽略表/矩阵单元内的数据区域
报表显示时列名显示忽略表/矩阵单元内的数据区域
RDLC SubReports Exporting to Excel Are Ignored
匯出至 Microsoft Excel (報表產生器 3.0 和 SSRS)
Reporting Service Export to Excel Problem
Subreports within table/matrix cells are ignored.

May try for tools to convert PDF to excel format.

Drop the table control from rdlc and Put your main report data into matrix control and put your sub reports below to maix control. Run your report and export again.It will be solved.

To be able to export SRS reports using Sub-reports to Excel, it is advisable to use List controls instead of Data Table. Once you have made this little change, the export to excel is just perfect. Infact it will automatically even freeze the rows in the page header so that when you scroll through the data that was included in the report header stays static.

第三方Dll檔_Aspose.Cells for Reporting Services

2013年8月8日 星期四

[技巧] DataGridViewComboBoxCell 取得 Value 的值

程式碼:
                DataGridView1.AutoGenerateColumns = False
                Dim cmb As New DataGridViewComboBoxColumn()
                cmb.HeaderText = "供應商簡稱"
                cmb.Name = "供應商簡稱"
                cmb.DataPropertyName = "供應商別"
                cmb.DisplayMember = "供應商簡稱"
                cmb.ValueMember = "供應商編號"
                cmb.DataSource = dt供應商
                DataGridView1.Columns.Insert(4, cmb)

原因:
假設某個Cell的 DisplayValue 為 "男", Value 為 "1"
當我們取用 DataGridView1(x,y).Value 時,
則其值為 ValueMember "1"
當我們要取值為男時為如何?

解決:
DataGridView1(col, row).FormattedValue.ToString

參考:
Getting Selected Text of combobox in datagridview
How to get the TEXT of Datagridview Combobox selected item?
DataGridView 控制項 (Windows Form)
請問DataGridViewComboBoxColumn 要如何取到改變selecteditem 後的值或文字

ProcessCmdKey方法让DataGridView按Enter回车键转到下一列的格
(讓ComboBoxColumn在下拉選項時, 解決出現二種模式...)

2013年8月7日 星期三

[除錯] 因為它會產生對 SetCurrentCellAddressCore 函式的可重新進入呼叫

問題:
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore

例子:
我在DataGridView的CellEnter事件
寫入以下的CODE:「DataGridView1.CurrentCell = DataGridView1(0,0)」
當進入(0,0)時, 因觸發CellEnter事件, 又將CurrentCell = (0,0), 又再次觸發事件
因此形成一個無窮迴圈
datagridview中CellValidating中出现无限循环

參考:
UI开发时, UI消息处理过程混乱的解决方法
Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function
RowLeave Event - Operation is not valid because it results in a reentrant call to the SetCurrentCellAddressCore function
DataGridView 控制項 (Windows Form)

[SQL] 簡體字存入資料庫之亂碼解決方式

環境:
WinXP(繁體)
SQL Server 2005(繁體)

目的:
讓簡體字存入資料庫而不變為亂碼[?]

解決:
1)
在 VB.Net 中使用 StrConv 函數進行繁簡字體轉換
將USER輸入的簡體字轉為繁體字存入資料庫
而在應用程式顯示資料時再由簡體字轉為繁體字

2)
MSSQL 簡體字存入亂碼解決方式
資料庫型態須定義為 ntext 或是 nchar , nvarchar
若定義成一般習慣前面未加 'n' 將只能放本國語系的文字
如果簡體字存入就會變成 '?'
而當 Insert 或是 UPDATE 資料時直接將簡體資料寫入也會變成 '?'
寫法必須改為 INSERT INTO table_name(test) VALUES(N'测试')
在寫入的資料前要加 N 他在存入資料庫時才會去呼掉到擴充字集..
如未加 N 他則是使用 big-5 字集...如果使用 .Net 裡面的 DataApdater 來
Update 資料也要注意 Parameters 裡面的關於每個參數的型態設定..
不然也會造成 '?' 的情形發生...................

參考:

[SQL] 取得資料表Table的欄位數量

select count(*) from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME = 'table_name' 
select count(*) from information_schema.columns where table_schema='資料庫名稱' and table_name='Table名稱';  

參考:
請問怎麼抓回table的欄位數??
請問我要如何計算一個 table 裡的欄位數量
請問怎麼抓回table的欄位數??
取得資料庫「資料表數」、「資料表名稱」,「資料表內欄位名稱」、「欄位數量」

2013年7月31日 星期三

[除錯] IIS(FTP)伺服器(繁體XP系統),無法上傳簡體檔案之解決!

原因:
繁體系統的IIS(FTP)伺服器,無法支援簡體中文!

解決:
1.改用支援簡體中文的FTP SERVER來架設!
2.限制檔案名稱僅可為「繁中」、「英數」!
3.將簡體轉為繁體,再上傳至FTP!
4.將FTP檔案存為(sn)-Guid,
而資料庫則存為 sn, 檔名+Guid as 檔名,
程式顯示時取檔名, 下載時則取(sn)-Guid...

Path.GetFileName(txbPath.Text.Trim).ToString & "+" & BitConverter.ToInt64(Guid.NewGuid().ToByteArray(), 0).ToString
傳回不重覆的長度 19 GUID 數字

 參考:
Directory 類別
DirectoryInfo 類別
HOW TO:列舉目錄和檔案
HOW TO:逐一查看目錄樹狀結構 (C# 程式設計手冊)
C#-批次處理目錄下所有檔案的方法
[C#]使用 Path 類別取得檔案或目錄路徑資訊
[C#]Winform選擇目錄路徑(FolderBrowserDialog)與選擇檔案名稱(OpenFileDialog)的用法
[programming-c#]把目錄下的檔案列出來, DirectoryInfo, StreamWriter
C#資料夾選擇框的實現(C#選擇資料夾,C# 打開資料夾,C# 流覽資料夾,C#怎麼選擇資料夾)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
//需加入參考 Microsoft.VisualBasic
using Microsoft.VisualBasic;

namespace trans2zhtw
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            if (!System.IO.Directory.Exists(this.txtDirectoryPath.Text))
            {
                //throw new ArgumentException();
                MessageBox.Show("請選擇目錄!!");
                return;
            }
               
            foreach (FileInfo file in RootDirs.GetFiles())
            {
                //MessageBox.Show(file.FullName);
                //MessageBox.Show(file.Directory.FullName); = MessageBox.Show(file.DirectoryName);
                FileSystem.Rename(file.FullName, file.DirectoryName + @"\" + Strings.StrConv(file.Name, VbStrConv.TraditionalChinese, 2052));
            }
        }

        DirectoryInfo RootDirs;
        DirectoryInfo[] SubDirs;
        FileInfo[] RootFiles;
        FileInfo[] SubFiles;
        private void button3_Click(object sender, EventArgs e)
        {
            richTextBox1.Clear();
            txtDirectoryPath.Clear();

            //選擇目錄
            FolderBrowserDialog path = new FolderBrowserDialog();
            //MessageBox.Show(path.ShowDialog().ToString());

            //if (System.IO.Directory.Exists(path.SelectedPath))
            if(path.ShowDialog()==DialogResult.OK)
            {
                this.txtDirectoryPath.Text = path.SelectedPath;

                //System.IO.DirectoryInfo
                RootDirs = new DirectoryInfo(txtDirectoryPath.Text);

                //取得所有檔案(含子目錄)
                RootFiles = RootDirs.GetFiles();

                //取得所有目錄(含子目錄)
                SubDirs = RootDirs.GetDirectories();

                richTextBox1.Text += "[主目錄][" + RootDirs.Name + "]" + "\n";
                foreach (FileInfo file in RootDirs.GetFiles())
                    richTextBox1.Text += file.Name + "\n";

                richTextBox1.Text += "\n";

                //取得主目錄下的子目錄, 不包含子目錄下的子目錄...
                foreach (DirectoryInfo sdir in SubDirs)
                {
                    richTextBox1.Text += "[子目錄][" + sdir.Name + "]" + "\n";

                    //取得目各子目錄下所有檔案
                    SubFiles = sdir.GetFiles();
                    foreach (FileInfo file in SubFiles)
                        richTextBox1.Text += file.Name + "\n";
                }
            }
        }
    }
}


[C#] 簡體亂碼轉換
繁體的IIS FTP 不能上傳簡體文件

請教簡體XP顯示繁體中文問題!
怎样才能是繁体和简体的操作系统都能看到简体FTP服务器里面的数据

[VB.NET]中文繁簡體轉換
在 VB.Net 中使用 StrConv 函數進行繁簡字體轉換

如何判断用户在Textbox输入的字符是否为繁体字
VB.NET判断字符是否是GB2312-80的汉字
简体繁体判断

FileSystem.Rename 方法
【VB.Net】使用rename修改檔名
如何使用FileInfo修改檔名

不同語系的轉碼、編碼 / HttpUtility.UrlEncode,Server.UrlEncode兩者差異
如何用 VB 或 VB.Net 來撰寫 ASP 的 Server.URLencode 函數

[SQL] 簡體字存入亂碼解決方式

參考:C#
How can I rename a file in C#?
C# 繁簡轉換效能大車拚
[C#]繁簡轉換好用的類別庫-Microsoft Visual Studio International Pack
C#簡繁轉換
C#中汉字的繁体和简体的相互转换的两个方法!

2013年7月30日 星期二

[除錯] TabControl 內的控制項 與 資料繫結 DataBindings, 卻檢查出空白值!

原因:
1.



控制項(TextBox、ComboBox, etc...) 在TabControl時, 且有資料繫結DataBinding(確實有值)
當儲存(檢查控制項是否空白)時, 卻會檢查出此控制項為空白!

2.
tabPage1有DataGridView綁定 bindingsource
當tabPage2為顯示頁時,此時執行 bindingsource.CancelEdit()
則會引發錯誤:
System.ArgumentOutOfRangeException 未處理
  Message=提供的資料列索引超出範圍。
參數名稱: rowIndex
  Source=System.Windows.Forms
  ParamName=rowIndex
  StackTrace:
       於 System.Windows.Forms.DataGridViewRowCollection.GetRowState(Int32 rowIndex)


解決:how to force all controls on all tab pages of a tab control to load/createhandle at once?
1.
//讓不同的tabPage的Control可以load DataBinding資料
foreach (var v in tabControl1.Controls.OfType<TabPage>())
     v.Show();

2.
執行程式時, 需每個TABPAGE都(手動)點過!

3.
        TabPage1.Show()
        TabPage2.Show()
        TabPage3.Show()
        TabPage4.Show()

4.
dgvM.DataSource = null;
bdNavi.BindingSource.RemoveCurrent();(或 bdNavi.BindingSource.CancelEdit();)  <--- 出錯點
bdNavi.BindingSource.ResetBindings(false);
dgvM.DataSource = bs;

2013年7月22日 星期一

[技巧] ReportViewer 動態改變TableRow是否顯示(或隱藏)

目的:
當某些欄位的值為0(或空白, 或其它條件)時, 則將此TableRow隱藏

解決:
「透過動態改變TableRow的Visibility」
選擇某個TableRow -> 屬性 -> Visibility -> 運算式
1) 一個欄位來決定Visibility
=iif(Fields!加班補貼.Value=0,true,false)

2) 二個欄位來決定Visibility
=iif(Fields!效率獎金.Value=0,iif(Fields!所得稅.Value=0,true,false),false)

3) N個欄位來決定Visibility
......

參考:

[學習] ReportViewer SubReport 子報表

CODE:使用 自定義事件 DemoSubreportProcessingEventHandler

[除錯] 無法在 System.Int32 和 System.String 上執行 Like 作業

1.你的ID欄位是數值並無法使用Like
2.在SQL語法可用"CAST(ID AS varchar) Like '" & FilterTextBox.Text & "%'"
3.PID的书籍类型修改为varchar后问题解决
4.bigDT.DefaultView.RowFilter = "CONVERT(SUBSTRING(CONVERT(date_posted, 'System.String'), 5, 4), 'System.Int32')=2012";


參考:
[MSDN]CAST 和 CONVERT (Transact-SQL)
[MSDN]DataColumn.Expression 属性
SQL函數 查詢SQL資料欄位相符的字串
MSSql 中Charindex ,Substring的使用
CHARINDEX (Transact-SQL)

DataView RowFilter遇到要篩選日期的方法 (空白或非空)
求助?无法在System.int32和System.string上执行“like”操作
无法在 System.Int32 和 System.String 上执行 Like 操作
問一個資料轉型的問題?
C#断开式数据库连接的DataView数据筛选的问题
DataTable使用方法
[SQL]數值轉字串
How to use LIKE operator in Dataview.RowFilter for Date Time or Numaric Fields using CONVERT


2013年7月10日 星期三

[SQL] 找出最新日期, 最舊日期, 最大值, 最小值

select e.*,f.姓名,f.部門,f.name from salary_month as e left join (select c.staff_sn,c.zhFname+c.zhName as 姓名,c.部門,d.name from employee as c left join (select a.* from employeePosition as a ,(select staff_sn,max(createDate) as createDate from employeePosition GROUP BY staff_sn) as b where a.staff_sn = b.staff_sn and a.createDate = b.createDate) as d on d.staff_sn = c.staff_sn) as f on e.emp_sn = f.staff_sn where e.日期 = '201306';

加入(身份2)
select e.*,f.姓名,f.部門,f.name,z.身份2 from salary_month as e left join (select a.emp_sn,a.身份2  from salary_basic as a, (select emp_sn,max(調整日期) as 調整日期 from salary_basic GROUP BY emp_sn) as b where a.emp_sn = b.emp_sn and a.調整日期 = b.調整日期 and a.身份2=1) as z on z.emp_sn = e.emp_sn  left join (select c.staff_sn,c.zhFname+c.zhName as 姓名,c.部門,d.name from employee as c left join (select a.* from employeePosition as a ,(select staff_sn,max(createDate) as createDate from employeePosition GROUP BY staff_sn) as b where a.staff_sn = b.staff_sn and a.createDate = b.createDate) as d on d.staff_sn = c.staff_sn) as f on e.emp_sn = f.staff_sn where e.日期 = '201306' and z.身份2 = 1;

參考:
[SQL] 找出職員最新一筆薪資調整紀錄並取得其職務名稱與任職日
SQL_找出最新日期、最舊日期、最大值、最小值
SQL的使用技巧_MAX()、MIN()與Group By、HAVING
請教一個麻煩的 SQL 語法?要找出每個會員的最新一筆訂單資料
請問如何在多個客戶下,找出每一個客戶跟我交易最近的日期
只抓取日期最大的單據資料
SELECT only the rows with MAX(DATE)
Need a little help, SQL Server 2000, having and max(date)
SQL语句练习实例之一——找出最近的两次晋升日期与工资额
Linq小技巧:日期處理
多個各自count之後還要join成一張表

2013年7月8日 星期一

[除錯] 大表(表頭)從小表(明細)取得計算的資料(sum,count,max,min,etc...), 並join到大表(表頭)

ERROR:
因為它並未包含在彙總函數或 GROUP BY


解決:
        Dim dt_month = staffDB.DataTable("select a.*,isnull(b.行政費用總計,0) as 行政費用總計 from [salary_month] a left join ( select salary_month_sn,sum(金額) as 行政費用總計 from [salary_month_others] Group by salary_month_sn ) b on a.sn = b.salary_month_sn where a.emp_sn = " & staffarr(0) & ";", Nothing, Nothing)


(可略)
        Dim dt_month_others = staffDB.DataTable("SELECT * FROM [salary_month_others] WHERE emp_sn =" & staffarr(0) & " and salary_month_sn = " & If(dt_month.Rows.Count > 0, dt_month.Rows(0)("sn").ToString, "0") & "", Nothing, Nothing)


參考:
EXISTS (Transact-SQL)
order by后有多个条件怎么写?
最近在使用Microsoft SQL Server Management Studio
SQL語法問題
請問group群組然後select
mssql group by的問題
grouping 排序的問題 (解決處)
sum left join 多次引发的问题
急..Help..Join 無明細資料時怎麼顯示主檔,且sum欄位
SQL group by 詳細用法
SQL group by用法
SQL::GROUP BY, COUNT and HAVING
多個各自count之後還要join成一張表

2013年5月21日 星期二

[學習] 四捨五入

[SQL]
select round(1.5446,2)
1.5400

select round(round(1.5446,3),2)
1.5500

select CAST(1.5446 AS decimal(9,2))
1.54

select CAST(1.546 AS decimal(9,2))
1.55

*資料型態decimal
  -生產數、工作分鐘 

統計數 =  Convert(Decimal(18,4) , 生產數 / 工作分鐘) * 60

[VB]
Module Module1
    Sub Main()
        Console.WriteLine((0.46).ToString("0"))
        'Console.WriteLine((1.45).ToString("0.0"))
        Console.WriteLine((0.5).ToString("0"))

        Console.WriteLine((0.46).ToString("f"))
        Console.WriteLine((0.5).ToString("f"))

        Console.WriteLine((4.625).ToString("0.00"))
        Console.WriteLine((4.645).ToString("0.00"))

        Console.WriteLine((4.625).ToString("f2"))
        Console.WriteLine((4.645).ToString("f2"))

        'Console.WriteLine((1.5).ToString("0"))
        Dim a As Double = 0.45
        Dim b As Decimal = 0.46
        'Dim c As Decimal = 4.625
        Console.WriteLine(Math.Round(a, 0, MidpointRounding.AwayFromZero))
        Console.WriteLine(Math.Round(b, 0, MidpointRounding.AwayFromZero))
        Console.WriteLine(Math.Round(4.625, 2, MidpointRounding.AwayFromZero))
        Console.WriteLine(Math.Round(CDec(4.645), 2, MidpointRounding.AwayFromZero))
        Console.Read()
    End Sub
End Module

-----------------

1. 整數以下四捨五入
     int(46410*0.05+0.5)=2321

2. 例 : 12.346 四捨五入至小數點以下一位
     int(12.346*10+0.5)/10=12.3

3. 例 : 12.346 四捨五入至小數點以下二位
     int(12.346*100+0.5)/100=12.35

參考:
浮點數計算結果更接近正解? 算錢用浮點,遲早被人扁

access中含四舍五入取值方法的查询sql语句
正確的四捨五入

[WIKI]數值簡化規則
C# Round (四捨五入) 使用 ToString()
利用VB.NET Format函数实现四舍五入功能
格式化输出-数字.ToString
c#中的常用ToString()方法总结
好用的string.Format或ToString()格式化字串的方法
[C#]簡單快速將各種數值字數轉成數字(string to int)
C#,double和decimal数据类型以截断的方式保留指定的小数位数

 '四捨五入
Public Function Round45(ByVal dblValue As Double) As Long
     Round45 = Fix(dblValue + 0.5 * Math.Sign(dblValue))
End Function

C#沒有四捨五入?只有五捨六入的涵數?
只要試試4.625與4.645兩個都對, 那才是真的對了

decimal 小數點位數 四捨五入
[C#]無條件進位,無條件捨去及四捨五入寫法

[ACCESS]單精準數運算Round取到小數位數問題
Round 函數

How To Implement Custom Rounding Procedures