//給ProgressBar最大執行時間
progressBar1.Maximum = 10 * 1000;
string strMessage = string.Empty;
//取得、控制執行緒,目前狀態
Thread t = new Thread(database);
t.Start();
//以ProgressBar最長時間,跑迴圈,影響ProgressBar進度
for (int i=0;i<10001;i++)
{
progressBar1.Value = i;
if (progressBar1.Maximum == progressBar1.Value && !t.Join(10 * 1000))
{
strMessage = "完成";
break;
}
//執行緒是否執行超過指定時間
if (!t.Join(10 * 1000))
{
strMessage = "Done";
//強制結束執行緒
t.Abort();
break;
}
}
if (progressBar1.Maximum == progressBar1.Value && !t.Join(10 * 1000))
{
strMessage = "完成";
}
MessageBox.Show(strMessage);
//給Thread的Function
public void database()
{
OracleConnection conn = new OracleConnection("Data Source=DB;User Id=abc;Password=abcd;");
OracleCommand cmd = new OracleCommand();
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"INSERT INTO Tablename VALUES('123','1234','abc')";
conn.Open();
cmd.ExecuteNonQuery();
conn.Close();
}
2011年12月20日 星期二
2011年12月13日 星期二
{C#} 多個DataTable放入同一個DataSet
一般式:
DataSet ds = new DataSet();
DataTable dt = new Datatable();
DataTable dt2 = new Datatable();
ds.Table.Add(dt,"table1");
ds.Table.Add(dt2,"table2");
資料庫方式:
using System.Data.OracleClient;
DataSet ds = new DataSet();
string sql = "select * from abc";
OracleDataAdapter da= new OracleDataAdapter(sql, conn);
da.Fill(ds, "table1");
string sql = "select * from abc2";
OleDbDataAdapter da= new OleDbDataAdapter(sql, conn);
da.Fill(ds, "table2");
DataSet ds = new DataSet();
DataTable dt = new Datatable();
DataTable dt2 = new Datatable();
ds.Table.Add(dt,"table1");
ds.Table.Add(dt2,"table2");
資料庫方式:
using System.Data.OracleClient;
DataSet ds = new DataSet();
string sql = "select * from abc";
OracleDataAdapter da= new OracleDataAdapter(sql, conn);
da.Fill(ds, "table1");
string sql = "select * from abc2";
OleDbDataAdapter da= new OleDbDataAdapter(sql, conn);
da.Fill(ds, "table2");
{C#} 對資料庫新增刪除修改多筆(Transaction)-Oracle為例
寫法一、
OracleTransaction txn = conn.BeginTransaction();
txn.Commit();
txn.Dispose();
conn.Close();
寫法二、
cmd.Transaction=conn.BeginTransaction();
cmd.Transaction.commit();
OracleTransaction txn = conn.BeginTransaction();
txn.Commit();
txn.Dispose();
conn.Close();
寫法二、
cmd.Transaction=conn.BeginTransaction();
cmd.Transaction.commit();
{Oracle} ORA CODE(持續更新;更新時間:10/01)
1.ORA-00913: too many values
前題:在INSERT INTO ABC@ccc.world SELECT * FROM ABC WHERE id = :Id
的語法下,產生ORA-00913
解惑:ABC@ccc.world Table欄位數與ABC Table欄位數不符而致
2.ORA-01795:
前題:SELECT * FROM ABC WHERE column in('1','2',.........................................)
解惑:因in語法中超過1000筆資料造成錯誤,其將語法改為 SELECT * FROM ABC WHERE
column in('1'......) or column in('1001',...............)
3.ORA-00904:invalid identifier
前題:SELECT * FROM ABC WHERE column='y'
解惑:語法中column名稱打錯,不在ABC Table中
4.ORA-01722:invalid number
前題:SELECT To_char(abc,'yyyy') FROM ABC
解惑:轉型失敗,查abc欄位內值是否有無法轉型的格式
5.ORA-00979: not a GROUP BY expression
前題:SELECT column2 FROM ABC GROUP BY column1
解惑: column1不在select list中,無法Group
6.ORA-01843:not a valid month
前題:SELECT TO_CHAR(columnDate,'yyyy-MM-dd') FROM ABC WHERE columnDate between '2012-1月-01' AND '2013-1月-01'
解惑: columnDate日期格式如有中文,勿直接Where中文格式;改寫為
SELECT TO_CHAR(columnDate,'yyyy-MM-dd') FROM ABC WHERE TO_CHAR(columnDate,'yyyy-MM-dd') between '2012-01-01' AND '2013-01-01';
前題:在INSERT INTO ABC@ccc.world SELECT * FROM ABC WHERE id = :Id
的語法下,產生ORA-00913
解惑:ABC@ccc.world Table欄位數與ABC Table欄位數不符而致
2.ORA-01795:
前題:SELECT * FROM ABC WHERE column in('1','2',.........................................)
解惑:因in語法中超過1000筆資料造成錯誤,其將語法改為 SELECT * FROM ABC WHERE
column in('1'......) or column in('1001',...............)
3.ORA-00904:invalid identifier
前題:SELECT * FROM ABC WHERE column='y'
解惑:語法中column名稱打錯,不在ABC Table中
4.ORA-01722:invalid number
前題:SELECT To_char(abc,'yyyy') FROM ABC
解惑:轉型失敗,查abc欄位內值是否有無法轉型的格式
5.ORA-00979: not a GROUP BY expression
前題:SELECT column2 FROM ABC GROUP BY column1
解惑: column1不在select list中,無法Group
6.ORA-01843:not a valid month
前題:SELECT TO_CHAR(columnDate,'yyyy-MM-dd') FROM ABC WHERE columnDate between '2012-1月-01' AND '2013-1月-01'
解惑: columnDate日期格式如有中文,勿直接Where中文格式;改寫為
SELECT TO_CHAR(columnDate,'yyyy-MM-dd') FROM ABC WHERE TO_CHAR(columnDate,'yyyy-MM-dd') between '2012-01-01' AND '2013-01-01';
2011年12月8日 星期四
{VB} 函數參考位罝
VarType 函數
http://yuan.yocjh.kh.edu.tw/%E6%95%99%E6%9D%90/vb%E5%87%BD%E6%95%B8.htm
http://yes.nctu.edu.tw/vb/6_Func/VarType.htm
InStrRev-->從右邊找符合字串
IsNumeric-->字串整串是數字就傳回True
從尾端搜尋字串位置
InstrRev(string,searchstr)
判定變數是否為陣列
IsArray(varname)
http://yuan.yocjh.kh.edu.tw/%E6%95%99%E6%9D%90/vb%E5%87%BD%E6%95%B8.htm
http://yes.nctu.edu.tw/vb/6_Func/VarType.htm
InStrRev-->從右邊找符合字串
IsNumeric-->字串整串是數字就傳回True
從尾端搜尋字串位置
InstrRev(string,searchstr)
判定變數是否為陣列
IsArray(varname)
2011年12月5日 星期一
{C#} 建立文件夾與檢查資料夾是否存在
string activeDirFilename="D:/Log_";
//建立文件夾路徑
string newPath = string.Format("{0}{1}", activeDirFilename, DateTime.Now.ToString("yyyyMMddHHmmss"));
//資料夾下再建立資料夾
//string newPath = System.IO.Path.Combine(activeDirFilename, DateTime.Now.ToString("yyyyMMddHHmmss"));
//建立指定路徑的資料夾
System.IO.Directory.CreateDirectory(newPath);
//建立文字檔,放入建立好的資料夾下
StreamWriter sr = new StreamWriter(string.Format("{0}/Log_{1}_{2}.txt", newPath, "abc", DateTime.Now.ToString("yyyyMMddHHmmss")));
sr.WriteLine("test");
sr.Close();
-------------------------------------------我是分隔線-----------------------------------------------------------------
//Check 資料夾是否存在,不存在則建立
if (!Directory.Exists(newPath))
Directory.CreateDirectory(newPath);
//建立文件夾路徑
string newPath = string.Format("{0}{1}", activeDirFilename, DateTime.Now.ToString("yyyyMMddHHmmss"));
//資料夾下再建立資料夾
//string newPath = System.IO.Path.Combine(activeDirFilename, DateTime.Now.ToString("yyyyMMddHHmmss"));
//建立指定路徑的資料夾
System.IO.Directory.CreateDirectory(newPath);
//建立文字檔,放入建立好的資料夾下
StreamWriter sr = new StreamWriter(string.Format("{0}/Log_{1}_{2}.txt", newPath, "abc", DateTime.Now.ToString("yyyyMMddHHmmss")));
sr.WriteLine("test");
sr.Close();
-------------------------------------------我是分隔線-----------------------------------------------------------------
//Check 資料夾是否存在,不存在則建立
if (!Directory.Exists(newPath))
Directory.CreateDirectory(newPath);
{XML} XML 設定可顯示空白
1)XML中,屬性:space
a.xml:space=preserve 可顯示空白
b.xml:space=default 不顯示空白
參考資料來源:http://taoistwar.iteye.com/blog/373998
2)在節點上附上space 屬性,其下所有節點都將可接受空白
參考資料來源:http://msdn.microsoft.com/zh-tw/library/ms788746(v=vs.90).aspx
3)設定於code中(C#)--xml無呈現空白,在load到程式中前,轉向可讀取空白
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.Load("book.xml");
此一方法在直接讀取xml時,無法顯示空白,但利用程式轉換,即可看到空白
參考資料來源:http://msdn.microsoft.com/zh-tw/library/system.xml.xmldocument.preservewhitespace(v=vs.80).aspx
a.xml:space=preserve 可顯示空白
b.xml:space=default 不顯示空白
參考資料來源:http://taoistwar.iteye.com/blog/373998
2)在節點上附上space 屬性,其下所有節點都將可接受空白
參考資料來源:http://msdn.microsoft.com/zh-tw/library/ms788746(v=vs.90).aspx
3)設定於code中(C#)--xml無呈現空白,在load到程式中前,轉向可讀取空白
XmlDocument doc = new XmlDocument();
doc.PreserveWhitespace = true;
doc.Load("book.xml");
此一方法在直接讀取xml時,無法顯示空白,但利用程式轉換,即可看到空白
參考資料來源:http://msdn.microsoft.com/zh-tw/library/system.xml.xmldocument.preservewhitespace(v=vs.80).aspx
2011年12月2日 星期五
{C#} enum 列舉用法
//宣告 列舉
public enum compare { maximum, minimum,noncondition }
switch (compare)
{
case compare.maximum:
break;
case compare.minimum:
break;
case compare.noncondition:
break;
}
public enum compare { maximum, minimum,noncondition }
switch (compare)
{
case compare.maximum:
break;
case compare.minimum:
break;
case compare.noncondition:
break;
}
{C#}Trim()系列用法
Trim()--移除前後的空白
string str = "i come back now ohoh w";
MessageBox.Show(str.Trim("i come hw".ToCharArray()));
Result: back n
//刪除前後符合的字元,直到前後各自沒有符合的單字為止
TrimStart()--移除前方空白
string str = "i come back now ohoh w";
MessageBox.Show(str.Trim().TrimStart("i come ba".ToCharArray()));
Result: k now ohoh w
//刪除前面符合的字元,直到沒有符合的單字為止
TrimEnd()--移除後方空白
string str = "i come back now ohoh w";
MessageBox.Show(str.Trim().TrimEnd("ohoh w".ToCharArray()));
Result: i com back n
//刪除後面符合的字元,直到沒有符合的單字為止
string str = "i come back now ohoh w";
MessageBox.Show(str.Trim("i come hw".ToCharArray()));
Result: back n
//刪除前後符合的字元,直到前後各自沒有符合的單字為止
TrimStart()--移除前方空白
string str = "i come back now ohoh w";
MessageBox.Show(str.Trim().TrimStart("i come ba".ToCharArray()));
Result: k now ohoh w
//刪除前面符合的字元,直到沒有符合的單字為止
TrimEnd()--移除後方空白
string str = "i come back now ohoh w";
MessageBox.Show(str.Trim().TrimEnd("ohoh w".ToCharArray()));
Result: i com back n
//刪除後面符合的字元,直到沒有符合的單字為止
{C#-Remote} new與呼叫 RemoteObjects 寫法
RemoteObjects obj = new RemoteObjects(ConfigurationSettings.AppSettings["ServerConnString"]);
RuleProcessor oRuleProcessor = (IRuleProcessor)obj.GetRemoteObject(ObjectList.RuleProcessor);
//這二行是一組的,obj是去new遠端物件,
//再透過obj去取放在遠端的RuleProcessor
//本機寫法,不透過遠端
//所以改 RuleProcessor ,把這個new的對象改成我們本機的
RuleProcessor oRuleProcessor = new RuleProcessor();
//遠端呼叫RuleProcessor中的方法
IProcessSpecialData oSpecialProcessor = oRuleProcessor.ProcessSpecialData(Id);
RuleProcessor oRuleProcessor = (IRuleProcessor)obj.GetRemoteObject(ObjectList.RuleProcessor);
//這二行是一組的,obj是去new遠端物件,
//再透過obj去取放在遠端的RuleProcessor
//本機寫法,不透過遠端
//所以改 RuleProcessor ,把這個new的對象改成我們本機的
RuleProcessor oRuleProcessor = new RuleProcessor();
//遠端呼叫RuleProcessor中的方法
IProcessSpecialData oSpecialProcessor = oRuleProcessor.ProcessSpecialData(Id);
{Oracle} join 語法-未完全
RIGHT JOIN:
寫法一、
select * from
(select charg from ABC where charg is not null order by charg desc)a
,
(select aufnr ,anred from CDE)b
where a.charg(+)=(substr(b.aufnr,6))
寫法二、
select id from
ABC A RIGHT JOIN CDE B
ON a.ID=b.ID
意義:
依CDE的表格為準,只要CDE有的,全列出來
參考:http://www.cnblogs.com/helong/articles/2088535.html
寫法一、
select * from
(select charg from ABC where charg is not null order by charg desc)a
,
(select aufnr ,anred from CDE)b
where a.charg(+)=(substr(b.aufnr,6))
寫法二、
select id from
ABC A RIGHT JOIN CDE B
ON a.ID=b.ID
意義:
依CDE的表格為準,只要CDE有的,全列出來
參考:http://www.cnblogs.com/helong/articles/2088535.html
2011年12月1日 星期四
{C#}StringBuilder數據清空
將StringBuilder內的數據清空
using System.Text;
StringBuilder sb=new StringBuilder();
for(int j=1 ;j<aryParms.Length;j++)
{
sb.AppendFormat("{0},",aryParms[j]);
}
//清空數據
sb.Remove(0, sb.Length);
StringBuilder在程序 會自動釋放資源
StringBuilder原理介紹--
http://programer.blog.richiestyle.org/2008/05/c-stringbuilder.html
using System.Text;
StringBuilder sb=new StringBuilder();
for(int j=1 ;j<aryParms.Length;j++)
{
sb.AppendFormat("{0},",aryParms[j]);
}
//清空數據
sb.Remove(0, sb.Length);
StringBuilder在程序 會自動釋放資源
StringBuilder原理介紹--
http://programer.blog.richiestyle.org/2008/05/c-stringbuilder.html
{C#-IBM_DB2}DB2連結
using IBM.Data.DB2;
using IBM.Data.DB2Types;
DB2Connection conn = new DB2Connection();
DB2Command cmd = new DB2Command();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ABC"].ConnectionString;
cmd.Connection = conn;cmd.CommandType = CommandType.Text;
DB2DataAdapter da = new DB2DataAdapter(cmd);
DataSet ds = new DataSet();
cmd.Parameters.Clear();
cmd.Parameters.Add("@MO", DB2Type.VarChar, 16).Value = mo;
cmd.CommandText = @"SELECT *
FROM abc
WHERE aufnr=LPAD(@MO,12,'0')";
ds = null;
ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
return ds;
using IBM.Data.DB2Types;
DB2Connection conn = new DB2Connection();
DB2Command cmd = new DB2Command();
conn.ConnectionString = ConfigurationManager.ConnectionStrings["ABC"].ConnectionString;
cmd.Connection = conn;cmd.CommandType = CommandType.Text;
DB2DataAdapter da = new DB2DataAdapter(cmd);
DataSet ds = new DataSet();
cmd.Parameters.Clear();
cmd.Parameters.Add("@MO", DB2Type.VarChar, 16).Value = mo;
cmd.CommandText = @"SELECT *
FROM abc
WHERE aufnr=LPAD(@MO,12,'0')";
ds = null;
ds = new DataSet();
conn.Open();
da.Fill(ds);
conn.Close();
return ds;
2011年11月30日 星期三
{C#}Enter功能如同Tab功能
using System.Windows.Forms;
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
protected override bool ProcessCmdKey(ref Message msg, Keys keyData)
{
if (keyData == Keys.Enter)
{
SendKeys.Send("{TAB}");
return true;
}
return base.ProcessCmdKey(ref msg, keyData);
}
{VB6}透過週期找出所屬週期的第一日日期
以下範例為
A:2011/01/01為第一周,則第二週的第一日日期為何?Q:2011/01/03
Private Sub Command1_Click()
Dim iDate As Date '指定第一周日期
Dim i As Long '指定週數
iDate = "2011-01-01"
i = 2
iDate = iDate + (i - 1) * 7 - 1
'Weekday(第一周日期,星期幾為新的一週)
iDate = iDate - Weekday(iDate, vbMonday) + 1
'結果顯示
Label1.Caption = iDate
End Sub
A:2011/01/01為第一周,則第二週的第一日日期為何?Q:2011/01/03
Private Sub Command1_Click()
Dim iDate As Date '指定第一周日期
Dim i As Long '指定週數
iDate = "2011-01-01"
i = 2
iDate = iDate + (i - 1) * 7 - 1
'Weekday(第一周日期,星期幾為新的一週)
iDate = iDate - Weekday(iDate, vbMonday) + 1
'結果顯示
Label1.Caption = iDate
End Sub
{C#-SQL資料庫}OleDb connection寫法
OleDbConnection conn = new OleDbConnection();
OleDbCommand cmd = new OleDbCommand();
conn.ConnectionString = @"Provider=MSDAORA;Data Source=xxxx;User Id=xxxxx;Password=xxxxxx;";
//conn.ConnectionString = ConfigurationManager.ConnectionStrings["cimdb-ConfigLab"].ConnectionString;
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"select * From abc where aufnr ='xx' ";
conn.Open();
//取得第一筆第一欄資料
object s = cmd.ExecuteScalar();
conn.Close();
this.textBox1.Text = s.ToString();
OleDbCommand cmd = new OleDbCommand();
conn.ConnectionString = @"Provider=MSDAORA;Data Source=xxxx;User Id=xxxxx;Password=xxxxxx;";
//conn.ConnectionString = ConfigurationManager.ConnectionStrings["cimdb-ConfigLab"].ConnectionString;
cmd.Connection = conn;
cmd.CommandType = CommandType.Text;
cmd.CommandText = @"select * From abc where aufnr ='xx' ";
conn.Open();
//取得第一筆第一欄資料
object s = cmd.ExecuteScalar();
conn.Close();
this.textBox1.Text = s.ToString();
訂閱:
文章 (Atom)