原始碼:
Function_A 初始化ComboBox內容選擇值
DataTable dt=new DataTable("ExchangeRateType");
dt.Columns.Add("en", typeof(Int16));
dt.Columns.Add("zh", typeof(string));
dt.Rows.Add("0", "×(乘)");
dt.Rows.Add("1", "÷(除)");
cbo_ExchangeRateType.DisplayMember = "zh";
cbo_ExchangeRateType.ValueMember = "en";
cbo_ExchangeRateType.DataSource = dt;
cbo_ExchangeRateUSDType.DisplayMember = "zh";
cbo_ExchangeRateUSDType.ValueMember = "en";
cbo_ExchangeRateUSDType.DataSource = dt.DefaultView ;
Function_B 從資料庫撈資料
dt = GetDataSet(OriginFindQry).Tables[0].Copy();
dt.TableName = _TblName;
if (ds.Tables.Contains(_TblName))
{
ds.Tables[_TblName].Dispose();
ds.Tables.Remove(_TblName);
}
ds.Tables.Add(dt);
Function_C 為每個控制項DataBinding
foreach (Control item in this.tableLayoutPanel1.Controls)
{
item.DataBindings.Clear();
}
txt_CustomerOrderNo.DataBindings.Clear();
txt_ExchangeRate.DataBindings.Clear();
txt_ExchangeRateUSD.DataBindings.Clear();
cbo_ExchangeRateType.DataBindings.Clear();
cbo_ExchangeRateUSDType.DataBindings.Clear();
bs_tblT訂單統計資料表.DataMember = null;
bs_tblT訂單統計資料表.DataSource = null;
bs_tblT訂單統計資料表.Clear();
bs_tblT訂單統計資料表.DataMember = _TblName;
bs_tblT訂單統計資料表.DataSource = ds;
this.bindingNavigator1.BindingSource = bs_tblT訂單統計資料表;
dataGridView1.DataSource = bs_tblT訂單統計資料表;
cbo_ExchangeRateType.DataBindings.Add("SelectedValue", bs_tblT訂單統計資料表, "ExchangeRateType");
cbo_ExchangeRateUSDType.DataBindings.Add("SelectedValue", bs_tblT訂單統計資料表, "ExchangeRateUSDType");
問題: 紫色底為錯誤發生點
(1)錯誤訊息:
bs_tblT訂單統計資料表.DataMember = null;
bs_tblT訂單統計資料表.DataSource = null;
bs_tblT訂單統計資料表.Clear();
========
(2)錯誤訊息:
//bs_tblT訂單統計資料表.DataMember = null;
bs_tblT訂單統計資料表.DataSource = null;
bs_tblT訂單統計資料表.Clear();
========
(3)錯誤訊息: 無法清除這個清單
//bs_tblT訂單統計資料表.DataMember = null;
//bs_tblT訂單統計資料表.DataSource = null;
bs_tblT訂單統計資料表.Clear();
原因:
解決:
cbo_ExchangeRateType.DataBindings.Clear();
參考:
[除錯] 無法繫結至 DataSource 上的屬性或欄位 或 無法清除這個清單
疑難排解例外狀況:System.InvalidCastException
InvalidCastException 類別
关于模板控件如何实现多数据源绑定的问题
2014年2月10日 星期一
[閱讀] 32bit系統VirtualBox安裝64bit系統(Win7)
1.首先CPU必須支援虛擬化技術
2.進入實體Bios進入CPU選項開啟虛擬化技術
3.VBox選擇安裝Win7X64bit即可
參考:
virtual box不能裝win7 64bit
殘念 下次買電腦CPU要支援Virtualization
VirtualBox安裝Windows7
How to Install Retail Mac Os X 10.8.2 Mountain Lion on Asus P8B75-M LX + update to 10.8.4
2.進入實體Bios進入CPU選項開啟虛擬化技術
3.VBox選擇安裝Win7X64bit即可
參考:
virtual box不能裝win7 64bit
殘念 下次買電腦CPU要支援Virtualization
VirtualBox安裝Windows7
How to Install Retail Mac Os X 10.8.2 Mountain Lion on Asus P8B75-M LX + update to 10.8.4
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 做更新?
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
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 函數
在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)
承自 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年11月12日 星期二
[除錯] 沒有足夠權限以存取 temp 目錄
[錯誤訊息]
System.UnauthorizedAccessException: Access to the temp directory is denied.
沒有足夠權限以存取 temp 目錄 SERVER1\Administrator
參考:
UnauthorizedAccessException 類別
System.UnauthorizedAccessException: 拒絕存取路徑
檔案複製出現UnauthorizedAccessException錯誤
unauthorizedaccessexception 拒絕存取路徑
Error: Access to the temp directory is denied.
xmlserializer problem
ASP.NET Access to the temp directory is denied
其它參考:
疑難排解程式碼存取安全性之例外狀況
當您嘗試存取檔案快取根目錄時發生 UnauthorizedAccessException
System.UnauthorizedAccessException: Access to the temp directory is denied.
沒有足夠權限以存取 temp 目錄 SERVER1\Administrator
參考:
UnauthorizedAccessException 類別
System.UnauthorizedAccessException: 拒絕存取路徑
檔案複製出現UnauthorizedAccessException錯誤
unauthorizedaccessexception 拒絕存取路徑
Error: Access to the temp directory is denied.
xmlserializer problem
ASP.NET Access to the temp directory is denied
其它參考:
疑難排解程式碼存取安全性之例外狀況
當您嘗試存取檔案快取根目錄時發生 UnauthorizedAccessException
訂閱:
文章 (Atom)