uuuuu
i'm possible
2012年11月7日 星期三
[C#]dr.delete
http://msdn.microsoft.com/zh-tw/library/ww3k31w0(v=VS.80).aspx
若RowState為added時
代表dt有加入值,但還沒接受變更
這個時候執行
foreach(DataRow dr in dt.Rows)
{
dr.delete();
}
會出現資料集已改變
這時,RowState的狀態是Detached
所以就會直接刪除
要在foreach之前就先執行dt.AcceptChange();
Rowstate的狀態才會是Delete
2012年9月21日 星期五
2012年8月27日 星期一
[C#] MessageBox.Show 應用
跳出錯誤Message視窗
跳出提示訊息方塊
跳出警告訊息方塊
跳出疑問訊息方塊
跳出疑問訊息方塊(YesNoCancel)
public static void ShowError(string MessageText)
{
MessageBox.Show(MessageText, "錯誤", MessageBoxButtons.OK, MessageBoxIcon.Error);
}
跳出提示訊息方塊
public static void ShowHint(string MessageText)
{
MessageBox.Show(MessageText, "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);
}
跳出警告訊息方塊
public static void ShowWarning(string MessageText)
{
MessageBox.Show(MessageText, "警告", MessageBoxButtons.OK, MessageBoxIcon.Warning);
}
跳出疑問訊息方塊
public static bool ShowQuestion(string MessageText)
{
return MessageBox.Show(MessageText, "問題", MessageBoxButtons.YesNo, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button2).Equals(DialogResult.Yes);
}
跳出疑問訊息方塊(YesNoCancel)
public static DialogResult ShowConfirm(string MessageText)
{
return MessageBox.Show(MessageText, "問題", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question,
MessageBoxDefaultButton.Button3);
}
2012年8月8日 星期三
[SQL]存取各種資料庫前十筆的語法
存取各種資料庫前十筆的語法
1. ORACLE
SELECT * FROM TABLE1 WHERE ROWNUM<=N
2. INFORMIX
SELECT FIRST N * FROM TABLE1 where 1=1
3. DB2
SELECT * ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM WHERE ROWNUM<=N
或者
SELECT COLUMN FROM TABLE where 1=1 FETCH FIRST N ROWS ONLY
4. SQL SERVER
SELECT TOP N * FROM TABLE1 where 1=1
or
SET ROWCOUNT N SELECT * FROM TABLE1 where 1=1 SET ROWCOUNT N1
5. SYBASE
SET ROWCOUNT N SELECT * FROM TABLE1 where 1=1 SET ROWCOUNT N1
6. MYSQL
SELECT * FROM TABLE1 where 1=1 LIMIT N
7. FOXPRO
SELECT * TOP N FROM TABLE ORDER BY COLUMN
8. ACCESS
SELECT TOP N * FROM TABLE1
1. ORACLE
SELECT * FROM TABLE1 WHERE ROWNUM<=N
2. INFORMIX
SELECT FIRST N * FROM TABLE1 where 1=1
3. DB2
SELECT * ROW_NUMBER() OVER(ORDER BY COL1 DESC) AS ROWNUM WHERE ROWNUM<=N
或者
SELECT COLUMN FROM TABLE where 1=1 FETCH FIRST N ROWS ONLY
4. SQL SERVER
SELECT TOP N * FROM TABLE1 where 1=1
or
SET ROWCOUNT N SELECT * FROM TABLE1 where 1=1 SET ROWCOUNT N1
5. SYBASE
SET ROWCOUNT N SELECT * FROM TABLE1 where 1=1 SET ROWCOUNT N1
6. MYSQL
SELECT * FROM TABLE1 where 1=1 LIMIT N
7. FOXPRO
SELECT * TOP N FROM TABLE ORDER BY COLUMN
8. ACCESS
SELECT TOP N * FROM TABLE1
2012年8月7日 星期二
[C#]自動產生DataGridView
自動產生DataGridView
DataTable dt = GetScoreTypeTable();
//取得項目類別
DataTable dtItem = AssessScoreProxy.GetAssessItem(101, 8);
foreach (DataRow dr in dt.Rows)
{
TabPage tbpage = new TabPage();
tbpage.Location = new System.Drawing.Point(4, 24);
tbpage.Padding = new System.Windows.Forms.Padding(3);
tbpage.Size = new System.Drawing.Size(685, 539);
tbpage.Name = "tp" + dr["No"];
tbpage.Text = dr["Name"].ToString();
tbpage.TabIndex = Convert.ToInt16(dr["No"]);
tbpage.AutoScroll = true;
//是否自動顯示捲軸
tbpage.UseVisualStyleBackColor = true;
tabControl1.Controls.Add(tbpage);
DataGridView dgv = new DataGridView();
DataGridViewTextBoxColumn colItem = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn colScore = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn colTotScore = new DataGridViewTextBoxColumn();
DataGridViewTextBoxColumn colScored = new DataGridViewTextBoxColumn();
dgv.AllowUserToAddRows = false;
dgv.AllowUserToDeleteRows = false;
dgv.BackgroundColor = System.Drawing.SystemColors.Window;
dgv.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize;
dgv.Columns.Add(colItem);
dgv.Columns.Add(colScore);
dgv.Columns.Add(colTotScore);
dgv.Columns.Add(colScored);
dgv.Dock = System.Windows.Forms.DockStyle.Fill;
dgv.Location = new System.Drawing.Point(0, 0);
dgv.Name = "dgv";
dgv.RowHeadersWidth = 10;
dgv.RowTemplate.Height = 24;
dgv.Size = new System.Drawing.Size(685, 539);
dgv.TabIndex = 0;
// colItem
colItem.HeaderText = "項目";
colItem.Name = "colItem" + dr["No"];
colItem.ReadOnly = true;
colItem.Width = 150;
colItem.AutoSizeMode = System.Windows.Forms.DataGridViewAutoSizeColumnMode.Fill;
// colScore
colScore.HeaderText = "分數";
colScore.Name = "colScore" + dr["No"];
// colTotScore
colTotScore.HeaderText = "此項目所佔總分";
colTotScore.Name = "colTotScore" + dr["No"];
colTotScore.ReadOnly = true;
colTotScore.Width = 150;
// colScored
colScored.HeaderText = "此項目已評分數加總";
colScored.Name = "colScored" + dr["No"];
colScored.ReadOnly = true;
colScored.Width = 180;
DataRow[] drItem = dtItem.Select("ScoreType='" + dr["No"] + "'");
foreach (DataRow drI in drItem)
{
dgv.Rows.Add(drI["ScoreItemName"], "", drI["Percentage"], 0);
}
tbpage.Controls.Add(dgv);
}
2012年8月6日 星期一
[C#]自動產生物件
/// <summary>
/// 自動產生物件
/// </summary>
private void SetTabControlDefault()
{
int pagecount =10;
int count = 30;
//TabPage(1~10)自動產生
for (int J = 0; J < pagecount; J++)
{
TabPage tbpage = new TabPage();
tbpage.Location = new System.Drawing.Point(4, 24);
tbpage.Padding = new System.Windows.Forms.Padding(3);
tbpage.Size = new System.Drawing.Size(685, 539);
tbpage.Name = "tp" + J.ToString();
tbpage.Text = J.ToString();
tbpage.TabIndex = J;
tbpage.AutoScroll = true; //是否自動顯示捲軸
tbpage.UseVisualStyleBackColor = true;
tabControl1.Controls.Add(tbpage);
//label.textbox 每個tabPage各產生30個
for (int i = 0; i < count; i++)
{
Label lb = new Label(); //label
lb.Name = "lb" + tbpage.Name.ToString() + i.ToString();
lb.Text = "lb" + tbpage.Name.ToString() + i.ToString();
lb.AutoSize = true;
lb.Location = new System.Drawing.Point(15, 10 + i * 30);
lb.Size = new System.Drawing.Size(150, 25);
lb.TabIndex = i;
tbpage.Controls.Add(lb);
TextBox txt = new TextBox(); //textbox
txt.Name = "txt" + tbpage.Name.ToString() + i.ToString();
txt.Location = new System.Drawing.Point(150, 10 + i * 30);
txt.Size = new System.Drawing.Size(150, 25);
txt.TabIndex = i;
tbpage.Controls.Add(txt);
}
}
}
2012年7月5日 星期四
[C#]當條件成立.變更背景顏色
當條件成立時,將該列的背景顏色變更
private void dgv_CellFormatting(object sender,DataGridViewCellFormattingEventArgs e)
{
try
{
DataGridView dgv = (sender as DataGridView);
if (dgv.Columns["dgvIsSelf"].Index == e.ColumnIndex)
{
if (Convert.ToBoolean(e.Value) == true) //是自費時,該列的顏色為黃色
{
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.Yellow;
}
else
{
dgv.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.White;
}
}
}
catch (Exception ex)
{
ex.ToString();
}
}
訂閱:
文章 (Atom)