2009年12月3日 星期四

修正asp.net menu在google chrome 顯示不正常的方法

將以下的code 複製到 page load 即可。
(若有使用master page 只需copy在master page即可,若無,則需每一頁之page load都嵌入以下code)

If (Request.UserAgent.IndexOf("AppleWebKit") > 0) Then
Request.Browser.Adapters.Clear()
End If

2009年11月27日 星期五

存取遠端資料庫伺服器的方法

三種方法可擇一使用

1. 使用SQL Server Enterprise Manager工具


選擇某一SQL Server --> 安全性 --> 連結伺服器 --> 新增連結伺服器  在【一般】頁籤中的連結的伺服器欄位中輸入欲連結伺服器的網路名稱全名。
顯示畫面如下:



在【安全性】頁籤中,選擇【使用下列安全性條件進行連線】輸入帳號及密碼。
顯示畫面如下:



2. 在QUERY ANALYZER中輸入


EXEC sp_addlinkedserver ‘xxx.xxx.xxx.xxx’,N’SQLServer的名稱’

EXEC sp_addlinkedsrvlogin ‘xxx.xxx.xxx.xxx’,’false’,NULL,’使用者帳號’,’密碼’

註: 其中紅色字體的N就直接輸入N 代表後面的字是Unicode

3. 直接在SQL指令中加入遠端伺服器連結資訊


以下範例查詢cydc.cyu.edu.tw資料庫伺服器中person資料庫的dbo所擁有的baperson資料表

select *


from opendatasource('sqloledb','data source=cydc.cyu.edu.tw;user id=帳號;password=密碼').person.dbo.baperson

4. 不同使用方法的差異:


若使用上述1及2的方式只需事先於該SQL Server中執行一次註冊動作,往後執行SQL 指令時可直接使用以下的方法連結到遠端資料庫:

select *


from [cydc.cyu.edu.tw].person.dbo.baperson

若使用第3種方法的話,則只需於每次執行SQL 指令時加入相關的連結資訊即可,不需事先執行1及2的前置動作。

2009年11月26日 星期四

開啟沒有功能列的新視窗

Dim javascript As String
javascript = "window.open('aaa.aspx','','left=150,top=150,width=600,height=600,toolbar=0,resizable=0');"
Page.ClientScript.RegisterClientScriptBlock(GetType(Page), Me.ClientID, javascript, True)
Dim javascript As String
javascript = " "
Response.Write(javascript)

gridview列: 數位、貨幣和日期 顯示格式

形式 語法 結果 注釋


數字 {0:N2} 12.36

數字 {0:N0} 13

貨幣 {0:c2} $12.36

貨幣 {0:c4} $12.3656

貨幣 "¥{0:N2}" ¥12.36

科學計數法 {0:E3} 1.23E+001

百分數 {0:P} 12.25% P and p present the same.

日期 {0:D} 2006年11月25日

日期 {0:d} 2006-11-25

日期 {0:f} 2006年11月25日 10:30

日期 {0:F} 2006年11月25日 10:30:00

日期 {0:s} 2006-11-26 10:30:00

時間 {0:T} 10:30:00

在設置gridview等資料綁定控制項的模版列時,總要設置顯示的格式,這裏是我查詢一些資料後統計出來的。


還有一個常規的選項是用資料庫中默認的格式顯示。



四捨五入保留兩位小數:

double dValue = 0.2356;

double result = System.Math.Round(dValue,2);



直接用 i.ToString("0.00")



格式化

日期:

ToString("yyyy-MM-dd")

返回2004-9-7

時間:

ataFormatString="{0: HH:mm:ss}"

(:) 時間分隔符號。在某些區域設置中,可以使用其他字元表示時間分隔符號。時間分隔符號在格式化時間值時分隔小時、分鐘和秒。格式化輸出中用作時間分隔符號的實際字元由系統的 LocaleID 值確定。

(/) 日期分隔符號。在某些區域設置中,可以使用其他字元表示日期分隔符號。日期分隔符號在格式化日期值時分隔日、月和年。格式化輸出中用作日期分隔符號的實際字元由您的區域設置確定。

(%) 用於表明不論尾隨什麼字母,隨後字元都應該以單字母格式讀取。也用於表明單字母格式應以用戶定義格式讀取。有關詳細資訊,請參見下面的內容。

d 將日顯示為不帶前導零的數字(如 1)。如果這是用戶定義的數位格式中的唯一字元,請使用 %d。

dd 將日顯示為帶前導零的數字(如 01)。

ddd 將日顯示為縮寫形式(例如 Sun)。

dddd 將日顯示為全名(例如 Sunday)。

M 將月份顯示為不帶前導零的數字(如一月表示為 1)。如果這是用戶定義的數位格式中的唯一字元,請使用 %M。

MM 將月份顯示為帶前導零的數字(例如 01/12/01)。

MMM 將月份顯示為縮寫形式(例如 Jan)。

MMMM 將月份顯示為完整月份名(例如 January)。

gg 顯示時代/紀元字串(例如 A.D.)

h 使用 12 小時制將小時顯示為不帶前導零的數字(例如 1:15:15 PM)。如果這是用戶定義的數位格式中的唯一字元,請使用 %h。

hh 使用 12 小時制將小時顯示為帶前導零的數字(例如 01:15:15 PM)。

H 使用 24 小時制將小時顯示為不帶前導零的數字(例如 1:15:15)。如果這是用戶定義的數位格式中的唯一字元,請使用 %H。

HH 使用 24 小時制將小時顯示為帶前導零的數字(例如 01:15:15)。

m 將分鐘顯示為不帶前導零的數字(例如 12:1:15)。如果這是用戶定義的數位格式中的唯一字元,請使用 %m。

mm 將分鐘顯示為帶前導零的數字(例如 12:01:15)。

s 將秒顯示為不帶前導零的數字(例如 12:15:5)。如果這是用戶定義的數位格式中的唯一字元,請使用 %s。

ss 將秒顯示為帶前導零的數字(例如 12:15:05)。

F 顯示秒的小數部分。例如,ff 將精確顯示到百分之一秒,而 ffff 將精確顯示到萬分之一秒。用戶定義格式中最多可使用七個 f 符號。如果這是用戶定義的數位格式中的唯一字元,請使用 %f。

T 使用 12 小時制,並對中午之前的任一小時顯示大寫的 A,對中午到 11:59 P.M 之間的任一小時顯示大寫的 P。如果這是用戶定義的數位格式中的唯一字元,請使用 %t。

tt 使用 12 小時制,並對中午之前任一小時顯示大寫的 AM;對中午到 11:59 P.M 之間的任一小時顯示大寫的 PM。

y 將年份 (0-9) 顯示為不帶前導零的數字。如果這是用戶定義的數位格式中的唯一字元,請使用 %y。

yy 以帶前導零的兩位元數位格式顯示年份(如果適用)。

yyy 以四位元數位格式顯示年份。

yyyy 以四位元數位格式顯示年份。

z 顯示不帶前導零的時區偏移量(如 -8)。如果這是用戶定義的數位格式中的唯一字元,請使用 %z。

zz 顯示帶前導零的時區偏移量(例如 -08)

zzz 顯示完整的時區偏移量(例如 -08:00)

讀取Excel檔資料存到DB中

string xlsFullName = FileUpload1.PostedFile.FileName;
string FileName = FileUpload1.PostedFile.FileName.Substring(FileUpload1.PostedFile.FileName.LastIndexOf("\\") + 1, FileUpload1.PostedFile.FileName.Length - FileUpload1.PostedFile.FileName.LastIndexOf("\\") - 1);

//讀取路徑給Step2
Session["xlsFullName"] = xlsFullName;
Session["FileName"] = FileName;
//Session()
//HDR=Yes 代表 EXCEL 第一列為欄位名稱 IMEX=1 為將混合型態的資料一律以文字型態顯示
// string OleConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsFullName + "; Extended Properties= \"Excel 8.0;HDR=NO \" ";
string OleConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsFullName + ";Extended Properties='Excel 8.0;HDR=NO;'";
//string OleConStr = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + xlsFullName + ";Extended Properties=Excel 8.0;";
DataSet ds = new DataSet();
OleDbConnection OleCn = new OleDbConnection(OleConStr);
string strSQL = @"SELECT * FROM [Sheet1$]";
try
{
OleCn.Open();
OleDbDataAdapter oledbda = new OleDbDataAdapter(strSQL, OleCn);
oledbda.Fill(ds, "NewExcel");
//Table給新欄名
ds.Tables["NewExcel"].Columns[0].ColumnName = "C1";
ds.Tables["NewExcel"].Columns[1].ColumnName = "C2";
ds.Tables["NewExcel"].Columns[2].ColumnName = "C3";
ds.Tables["NewExcel"].Columns[3].ColumnName = "C4";
ds.Tables["NewExcel"].Columns[4].ColumnName = "C5";
ds.Tables["NewExcel"].Columns[5].ColumnName = "C6";
ds.Tables["NewExcel"].Columns[6].ColumnName = "C7";
ds.Tables["NewExcel"].Columns[7].ColumnName = "C8";

GridView1.DataSource = ds.Tables["NewExcel"];
GridView1.DataBind();
}
catch
{
String scriptString = @"

";
this.RegisterStartupScript("s", scriptString);
return;
}
}
}

其他參考資料:
 1. HOW TO:使用 ADO.NET 擷取與修改利用 Visual Basic .NET 之 Excel 活頁簿中的記錄
http://support.microsoft.com/kb/316934/zh-tw
2.ExcelADO 示範使用 ADO 在 Excel 活頁簿讀取和寫入資料的方法
http://support.microsoft.com/kb/278973/ZH-TW/
參考ExcelADO.exe檔
問題:
時機:使用者可能回自行要連接資料庫,但是ConnectionString太複雜不好撰寫
方法:事實上微軟已經把這個對話盒包裝起來,
包含:
1.建立ConnectionString
2.開啟*.udl檔案,讀入ConnectionString
3.寫入*.udl檔案,用已知的ConnectionString,幫你產生*.udl檔案

答案:
實做
1. 先加入參考->COM
C:\Program Files\Common Files\System\OLE DB\oledb32.dll

說明:這個檔案oledb32.dll,就是幫我們操作ConnectionString的物件,事實上早已存在(舊的OleDB物件),並不是.NET物件,之後VS.NET會幫我們產生一個For.NET的檔案,這是用來呼叫oledb32的.NET DLL檔


2. 再加入參考->.NET
adodb (C:\Program Files\Microsoft.NET\Primary Interop Assemblies\adodb.dll)
說明:因為oledb32是要利用ADO Object(不能利用ADO.net)來承接所產生出來的ConnectionString,所以我們必須要建立ADO物件
程式:
///
/// 啟動ConnectionString對話盒
///

/// 預設的ConnectionString
/// 回傳ConnectionString
public string OpenConnectionStringDialog(string vDefaultConnectionString)
{
MSDASC.DataLinksClass DataLinkObj = new MSDASC.DataLinksClass();
ADODB.ConnectionClass ConnObj = new ADODB.ConnectionClass();
ConnObj.ConnectionString = vDefaultConnectionString;
object TempConnObj = (object)ConnObj;
DataLinkObj.PromptEdit(ref TempConnObj);
return ConnObj.ConnectionString;
}

3. 說明:會傳入一個預設的ConnectionString可預帶之前的設定
備註:發布時一定要把oledb32.dll和Interop.MSDASC.dll一起發布給Client端

動態畫2D圖

Imports System.Drawing
Imports System.Drawing.Imaging
Imports System.Drawing.Drawing2D
Imports System.Drawing.Text
Imports System.Data.SqlClient
Imports System.Web.Configuration

Partial Class _Default

Inherits System.Web.UI.Page
Private _Width As Integer = 600
Private _Height As Integer = 600

Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load

Dim BitmapImage As New Bitmap(_Width, _Height, PixelFormat.Format32bppArgb)
Dim Canvas As Graphics = Graphics.FromImage(BitmapImage)
' 好了,現在我們取得 Graphics,在這張畫布畫圖,相當於畫在 Bitmap 上
' 填入漸層藍色當背景
Dim ClientArea As New Rectangle(New Point(0, 0), New Size(_Width, _Height))
Dim BlueGradientBrush As New LinearGradientBrush(New Point(0, 0), _
New Point(0, _Height), Color.White, Color.White)
Canvas.FillRectangle(BlueGradientBrush, ClientArea)
' 畫出邊框
Dim BluePen As New Pen(Color.Black, 2)
Canvas.DrawRectangle(BluePen, ClientArea)
Graphics_Loop(Canvas, "888888888888888", 5, 10, 100, 20)
Graphics_Loop(Canvas, "99999", 5, 35, 100, 20)

' 以標楷體 18 點斜體字樣秀出文字
'Dim SF As New StringFormat(StringFormatFlags.NoWrap Or _
' StringFormatFlags.NoFontFallback)
'SF.LineAlignment = StringAlignment.Near
'SF.Alignment = StringAlignment.Center
'Dim F As Font = New Font("標楷體", 18, FontStyle.Italic)
'ClientArea.Offset(0, 4)
'Canvas.DrawString(ContentString, F, Brushes.Black, _
' CType(ClientArea, RectangleF), SF)
'ClientArea.Offset(0, -4)

' 再裝飾一段底線文字
'Canvas.FillRectangle(Brushes.Black, 0, 30, _Width, 10)
'SF.LineAlignment = StringAlignment.Far
'SF.Alignment = StringAlignment.Center
'F = New Font("Arial", 8, FontStyle.Italic)
'Canvas.DrawString("Anti-phishing with Sign-in Seal", F, _
' Brushes.White, CType(ClientArea, RectangleF), SF)

' 輸出圖片到 Client 端
Response.Clear()
Response.ContentType = "image/jpeg"
BitmapImage.Save(Response.OutputStream, ImageFormat.Jpeg)
Response.End()
End Sub

Function Graphics_Loop(ByVal Canvas As Graphics, ByVal Txt As String, ByVal xv As Integer, ByVal yv As Integer, ByVal wv As Integer, ByVal hv As Integer)
Dim ClientArea As New Rectangle(New Point(xv, yv), New Size(wv, hv))
Dim BluePen As New Pen(Color.Black, 1)
Canvas.DrawRectangle(BluePen, ClientArea)
Dim SF As New StringFormat(StringFormatFlags.NoWrap Or _
StringFormatFlags.NoFontFallback)
SF.LineAlignment = StringAlignment.Near
SF.Alignment = StringAlignment.Center
Dim F As Font = New Font("標楷體", 12, FontStyle.Bold)
ClientArea.Offset(0, 4)
Canvas.DrawString(txt, F, Brushes.Black, _
CType(ClientArea, RectangleF), SF)
ClientArea.Offset(0, -4)
End Function
End Class

把aspx程式預先編譯的方法

指令
aspnet_compiler -v std -p d:\aspx\整個網頁目錄 d:\產生目標目錄

利用 BasePage 實作表單權限控管

來源:ASP.NET魔法學院

連結:http://itgroup.blueshop.com.tw/jeff377/blog?n=convew&i=2106

十幾行程式碼搞定 Master-Detail GridView(內含子 GridView)

來源:ASP.NET魔法學院
連結:http://itgroup.blueshop.com.tw/jeff377/blog?n=convew&i=2111

擴展 CommandField 類別 - 刪除提示訊息含欄位值

來源 : ASP.NET 魔法學院
在之前的「擴展 CommandField 類別 - 刪除提示訊息」文章中實作了 TBCommandField 類別,設定 DeleteConfirmMessage 屬性可以輕易設定刪除提示訊息。

這篇文章針對 TBCommandField 類別做進一步的擴展,我們希望在刪除訊息中可以加入指定的欄位值,讓使用者明確知道刪除的資料,例如刪除某個產品資料時,可以顯示這個產品的名稱在提示訊息中。

針對這個需求,在 TBCommandField 類別新增一個 DataField 屬性,設定刪除提示訊息中顯示欄位值的資料欄位名稱。因為要取得繫結的欄位資料,所以在 SetDeleteButton 私有方法中,設定刪除鈕 DataBinding 事件處理函式為 OnDataBindField,當 GridView 做 DataBind 時,就會引發子控制項的 DataBinding 事件,此時就會執行 OnDataBindField 方法,這時可以取得繫結的資料的 DataRowView,然後就可以從 DataRowView 中取得 DateField 的欄位值。

實作程式碼如下

Imports System
2 Imports System.Collections.Generic
3 Imports System.ComponentModel
4 Imports System.Text
5 Imports System.Web
6 Imports System.Web.UI
7 Imports System.Web.UI.WebControls
8
9
10 Public Class TBCommandField
11 Inherits CommandField
12
13 Private FDeleteConfirmMessage As String = String.Empty
14 Private FDataField As String = String.Empty
15
16 '''
17 ''' 刪除提示訊息。
18 '''

19 Public Property DeleteConfirmMessage() As String
20 Get
21 Return FDeleteConfirmMessage
22 End Get
23 Set(ByVal value As String)
24 FDeleteConfirmMessage = value
25 End Set
26 End Property
27
28 '''
29 ''' 刪除提示訊息顯示欄位值的資料欄位名稱。
30 '''

31 Public Property DataField() As String
32 Get
33 Return FDataField
34 End Get
35 Set(ByVal value As String)
36 FDataField = value
37 End Set
38 End Property
39
40 '''
41 ''' 初始化儲存格。
42 '''

43 '''
要初始化的儲存格。44 '''
儲存格類型。45 '''
儲存格狀態。46 '''
資料列之以零起始的索引。47 '''
48 Public Overrides Sub InitializeCell(ByVal cell As DataControlFieldCell, ByVal cellType As DataControlCellType, ByVal rowState As DataControlRowState, ByVal rowIndex As Integer)
49 MyBase.InitializeCell(cell, cellType, rowState, rowIndex)
50 If Me.ShowDeleteButton AndAlso Me.Visible AndAlso Me.DeleteConfirmMessage <> String.Empty Then
51 SetDeleteButton(cell)
52 End If
53 End Sub
54
55 '''
56 ''' 建立新的 TBCommandField 物件。
57 '''

58 Protected Overrides Function CreateField() As DataControlField
59 Return New TBCommandField()
60 End Function
61
62 '''
63 ''' 將目前 TBCommandField 物件的屬性複製到指定之 DataControlField 物件。
64 '''

65 '''
目的 DataControlField 物件。66 Protected Overrides Sub CopyProperties(ByVal NewField As DataControlField)
67 Dim oNewField As TBCommandField
68
69 oNewField = DirectCast(NewField, TBCommandField)
70 oNewField.DeleteConfirmMessage = Me.DeleteConfirmMessage
71 oNewField.DataField = Me.DataField
72 MyBase.CopyProperties(NewField)
73 End Sub
74
75 '''
76 ''' 設定刪除鈕。
77 '''

78 '''
儲存格。79 Private Sub SetDeleteButton(ByVal Cell As DataControlFieldCell)
80 Dim oControl As Control
81
82 For Each oControl In Cell.Controls
83 If TypeOf (oControl) Is IButtonControl Then
84 If DirectCast(oControl, IButtonControl).CommandName = "Delete" Then
85 '設定刪除鈕的 DataBinding 事件處理函式
86 AddHandler oControl.DataBinding, New EventHandler(AddressOf Me.OnDataBindField)
87 Exit Sub
88 End If
89 End If
90 Next
91 End Sub
92
93 '''
94 ''' 將欄位值繫結至 TBCommandField 物件。
95 '''

96 Protected Overridable Sub OnDataBindField(ByVal sender As Object, ByVal e As EventArgs)
97 Dim oControl As Control
98 Dim oDataItem As Object
99 Dim oDataRowView As Data.DataRowView
100 Dim sScript As String
101 Dim sMessage As String
102
103 oControl = DirectCast(sender, Control)
104
105 If Me.DataField <> String.Empty Then
106 '處理訊息中的欄位值
107 oDataItem = DataBinder.GetDataItem(oControl.NamingContainer)
108 oDataRowView = CType(oDataItem, Data.DataRowView)
109 sMessage = String.Format(Me.DeleteConfirmMessage, oDataRowView.Item(Me.DataField).ToString())
110 Else
111 sMessage = Me.DeleteConfirmMessage
112 End If
113
114 sMessage = Strings.Replace(sMessage, "'", "\'") '處理單引號
115 sScript = "if (confirm('" & sMessage & "')==false) {return false;}"
116 DirectCast(oControl, WebControl).Attributes("onclick") = sScript
117 End Sub
118
119 End Class

使用時在 aspx 程式碼中設定其 DeleteConfirmMessage 及 DateField 屬性就在刪除提示訊息加入欄位值。其中 DeleteConfirmMessage="確定刪除 {0} 這筆資料嗎?" 中的 {0} 就是 ProductName 欄位值顯示的位置。


1 >
view plain |



如何讓自己開發的.Net 元件顯示在.Net 元件參考的視窗Tab中 ?

目的:
讓自己開發的.Net 元件顯示在.Net 元件參考的視窗Tab中。

作者:chsteven
語言:
步驟:
各位要顯示在.Net Component參考視窗的技巧,重點在於要在Windows Registry中加上一個機碼,而機碼位置需新增於底下路徑:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\[您自己的機碼名稱]

然後在「預設值」這個值名稱中新增您的Component的實體目錄路徑。

舉例來說,我有一個AA.dll,路徑位於D:\Component\Test\AA.dll
所以我可以做以下動作:

1. 新增機碼
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\.NETFramework\AssemblyFolders\myTest

2. "預設值"的值新增為:
D:\Component\Test\

如此即可。
此外, .Net提供的安裝部署程式可以幫各位登錄Registry, 所以實際上在部署元件時, 可以用這個工具來協助。

如何避免報表程式被電腦中其他的作業中斷?

問題:
在跑一個很大的報表時,常會被電腦中其他的作業中斷,如何避免?

答案:
按「Ctrl-Alt-Del」叫出「Task Manager」,切換到「Processes」在「crw32.exe」上按下滑鼠右鍵選擇「Set Prority」à「High」。

如何跨欄合併DataGrid標頭欄位?

語言:Visual C# .NET
步驟:
1. 請試著在 DataGrid 物件的 ItemCreate 事件中加入以下程式碼
private void DataGrid1_ItemCreated(object sender, System.Web.UI.WebControls.DataGridItemEventArgs e) {

if ( e.Item.ItemType == ListItemType.Header ) {

TableCellCollection tcl = e.Item.Cells;

tcl.Clear();

tcl.Add( new TableHeaderCell() );

tcl[0].RowSpan = 2;

tcl[0].Text = "資料項目";



tcl.Add( new TableHeaderCell() );

tcl[1].ColumnSpan = 2;

tcl[1].Text = "會計科目借貸";

}

}

如何部署Crystal Report ?

目的:
使用安裝專案,部署Crystal Report。

作者:brian_wang
語言:
步驟:
照一般建立安裝專案,加入合併模組:

(1)regwiz.msm
(2)Managed_cht.msm
(3)managed.msm
(4)Database_Access.msm
(5)Database_Access_cht.msm
(6)dotnetfxredist_x86_cht.msm
其中(3)(6)項在建立完專案時自動加入到偵測到的相依性其餘需手動加入,在第(1)項的屬性中需設定license key(在屬性視窗中可找到) 。

license key( xxxxx-xxxxxxx-xxxxxxx)在說明中最後一個選項(關於 microsoft....)可以找到。
若是報表連結時使用到DataSet ,則須另外加入 VC_CRT.msm 及VC_STL.msm 兩個項目。且需先在檔案系統中增加系統資料夾 再將VC_CRT.msm 及VC_STL.msm 兩個項目的Module Retargetable Folder的屬性設為系統資料夾,接下來便開始建置...........

如何設計動態的Top N報表?

問題:
如何設計動態的Top N報表?

答案:
用Crystal Reports 9的「Add Command」新功能。

1. 撰寫一個Command其中用一個參數來控制要選出前幾個(N)群組。

Access版的SQL Command

SELECT TOP {?N} `Customer`.`Country`, SUM(`Customer`.`Last Year's Sales`) AS Sum_Last_Years_Sales

FROM `Customer` `Customer`

GROUP BY `Customer`.`Country`

ORDER BY SUM(`Customer`.`Last Year's Sales`) DESC



SQL Server版的SQL Command

SELECT TOP {?N} SUM("CUSTOMER"."Last Year's Sales")AS Sum_Last_Years_Sales,"CUSTOMER"."COUNTRY"

FROM "Xtreme"."dbo"."CUSTOMER" "CUSTOMER"

GROUP BY "CUSTOMER"."COUNTRY"

ORDER BY SUM("CUSTOMER"."Last Year's Sales") DESC

2. 同樣在「Add Command」裡加入一個Paramenter:名稱為N、型別為Number。

3. 把「Sum_Last_Years_Sales」及「COUNTRY」欄位放入「Details」區段。

重新整理報表。便可根據使用者輸入的數字,動態顯示前N大群組。

如何取得OS登入系統帳號

目的:
在Windows表單程式中取得登入作業系統帳號。

語言:C#
步驟:
1. 引用System.Security.Principal命名空間

using System.Security.Principal;

2. 加入以下程式碼:

WindowsPrincipal wp = new WindowsPrincipal(WindowsIdentity.GetCurrent());

3. 取得帳號:

wp.Identity.Name

如何取得自己的機器IP(非127.0.0.1)

目的:
取得自己的機器IP(非127.0.0.1)

語言:任何.NET語言
步驟:
如果是 client 的 IP,那麼可以用 Request.ServerVariables[ "REMOTE_ADDR" ] 來取得。如果是 server 的 IP,那麼可以用 Request.ServerVariables[ "LOCAL_ADDR" ] 來取得。

對了, 請不要用 http://localhost/xxx/xxx.aspx 的方式來瀏覽,因為 localhost 在 hosts table 裡的 IP 預設就是 127.0.0.1,看到的結果會不正確哦!

如何抓取Client的MAC(網卡的號碼)?

目的:
抓取Client的MAC(網卡的號碼)

語言:Visual C#.NET
步驟:
1. 使用以下範例程式碼
ManagementObjectSearcher query =new ManagementObjectSearcher("SELECT * FROM Win32_NetworkAdapterConfiguration") ;
ManagementObjectCollection queryCollection = query.Get();
foreach( ManagementObject mo in queryCollection )
{
if(mo["IPEnabled"].ToString() == "True")
MessageBox.Show(mo["MacAddress"].ToString());
}
有幾張網卡就會跑幾次,不過要確定該網卡有啟動喔,沒啟動抓不到。

如何在Visual Studio 除錯Client-Side Script

目的:
設定Visual Studio.NET工具,以利用它的除錯工具,對Client-Side Script進行單步除錯、設定中斷點,及查看變數。

作者:Adams
語言:
步驟:
1. 在 Internet Explorer, 將 Disable script debugging check box (停止指令碼偵錯)這個進階選項勾勾拿掉

2. 在 Visual Studio .NET,從選單選取Debug Processes ,將其貼附到IExplore.exe,在Running Document window,選取要除錯的.aspx

3. 在 Visual Studio .NET, 設定中斷點在妳要除錯的 client-side code

4. 在 Internet Explorer 按下 sumbit 測試