2009年12月7日 星期一

Gridview 設定 不斷行、欄位隱藏、設定欄寬

Protected Sub GridView1_RowCreated(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowCreated
If e.Row.RowType = DataControlRowType.DataRow Or e.Row.RowType = DataControlRowType.Header Then
'不斷行設定
For i As Integer = 0 To e.Row.Cells.Count - 1
e.Row.Cells(i).Attributes.Add("style", "word-break :keep-all ; word-wrap:keep-all")
Next
'欄位隱藏
e.Row.Cells(1).Visible = False
'設定欄寬
e.Row.Cells(0).Attributes.Add("style", "width:20px")
e.Row.Cells(2).Attributes.Add("style", "width:30px")
e.Row.Cells(3).Attributes.Add("style", "width:90px")
e.Row.Cells(4).Attributes.Add("style", "width:90px")
e.Row.Cells(5).Attributes.Add("style", "width:70px")
e.Row.Cells(6).Attributes.Add("style", "width:150px")
End If
End Sub

2009年11月28日 星期六

ASP.NET 產生 匯出 Excel 到Server端

假使要從Client產在一個excel檔到Server端
必須在web.config加上一個有權限執行excel的使用者
如:
<system.web>
<identity impersonate="true" userName ="Administrator" password ="123123"/>
</system.web>

參考自:
http://support.microsoft.com/default.aspx?scid=kb;EN-US;306022

Try
Dim oExcel As Object
Dim oBook As Object
Dim oSheet As Object

'Start a new workbook in Excel.
oExcel = CreateObject("Excel.Application")
oBook = oExcel.Workbooks.Add

For i As Integer = 0 To ds.Tables.Count - 1
oSheet = oBook.Worksheets.Add
'合併欄位
oSheet.Range("A1", "I1").Merge()
oSheet.Range("J1", "K1").Merge()
'文字置中
oSheet.Range("A1", "I1").HorizontalAlignment = Excel.XlHAlign.xlHAlignCenter
oSheet.Range("J1", "K1").HorizontalAlignment = Excel.XlHAlign.xlHAlignLeft
oSheet.cells(1, 1).Value = "自製工具個人分戶帳"
oSheet.cells(1, 10).Value = "資料日期: " & DateTime.Now.ToShortDateString
oSheet.cells(1, 1).Font.Bold = True
'加入外框線
oSheet.Range("A2", "K" & ds.Tables(i).Rows.Count + 2).Borders.LineStyle = 1
'強制轉型 不加這行的話如果字串是0002 匯到excel會變成2
oSheet.Cells.NumberFormatLocal = "@"
For j As Integer = 0 To ds.Tables(i).Rows.Count - 1
'Add data to cells of the first worksheet in the new workbook.
oSheet.Name = ds.Tables(i).Rows(j).Item(1)
'oSheet.Range("A1").Value = "Last Name"
oSheet.cells(2, 1).Value = "項次"
oSheet.cells(2, 2).Value = "借用人"
oSheet.cells(2, 3).Value = "借用人帳號"
oSheet.cells(j + 3, 1).value = RTrim(ds.Tables(i).Rows(j).Item(0))
oSheet.cells(j + 3, 2).value = RTrim(ds.Tables(i).Rows(j).Item(1))
oSheet.cells(j + 3, 3).value = RTrim(ds.Tables(i).Rows(j).Item(2))
'自動調整欄寬
oSheet.Columns("A:Z").EntireColumn.AutoFit()
Next
Next
'Save the Workbook and quit Excel.
'如果檔案已存在 則自動刪除
If System.IO.File.Exists("C:\" & filename & "borrow.xls") = True Then
System.IO.File.Delete("C:\" & filename & "borrow.xls")
End If
oBook.SaveAs("C:\" & filename & "borrow.xls")

oSheet = Nothing
oBook = Nothing
oExcel.Quit()
oExcel = Nothing
GC.Collect()

'KillExcel()
Catch ex As Exception

End Try

如果要強制刪除Excel的程序可用以下語法
不過要注意執行後會強制關掉畫面上所有的excel
Private Sub KillExcel()
Dim myProcesses() As Diagnostics.Process
Dim myProcess As Diagnostics.Process
' Returns array containing all instances of "EXCEL".
On Error Resume Next
myProcesses = Diagnostics.Process.GetProcessesByName("EXCEL")
For Each myProcess In myProcesses
myProcess.Kill()
Next
On Error GoTo 0
myProcesses = Nothing
myProcess = Nothing
End Sub

DataTable 加入流水編號方式

Dim dt as new DataTable
Dim column As New DataColumn("項次", Type.GetType("System.Int32"))
With column
.AutoIncrement = True
.AutoIncrementSeed = 1
.AutoIncrementStep = 1
End With
dt.Columns.Add(column)

2009年11月23日 星期一

輸出畫面為千分位 加逗號

SELECT convert(nvarchar,cast('12345.999' as money),1)

2009年11月17日 星期二

如何使 ASP.NET 元件 MENU 能夠更漂亮 CSS

套用以下基本CSS,再依個人審美觀做適當的修改
<asp:Menu ID="Menu1" runat="server" CssClass="menu_Main" DynamicHorizontalOffset="2"
Orientation="Horizontal" StaticSubMenuIndent="10px" Width="296px">
<StaticMenuStyle CssClass ="menu_StaticMenuStyle" />
<StaticMenuItemStyle  CssClass="menu_StaticMenuItemStyle " />
<StaticHoverStyle CssClass="menu_StaticHoverStyle" />
<StaticSelectedStyle CssClass="menu_StaticSelectedStyle"/>
<DynamicMenuStyle CssClass="menu_DynamicMenuStyle" BackColor="#F8F8D4" />
<DynamicSelectedStyle CssClass="menu_DynamicSelectedStyle"  />
<DynamicHoverStyle  CssClass ="menu_DynamicHoverStyle"/>
<Items>
</Items>
</asp:Menu>
/*menu style*/
.menu_Main{
height:30px;
}
.menu_StaticMenuStyle{
}
.menu_StaticMenuItemStyle {
width:70px;
font-size:15px;
/*HorizontalPadding="5px" VerticalPadding="2px"*/
}
.menu_StaticHoverStyle{
color:#FFFFFF;
background-color:#668BB2 ;
width:60px;
}
.menu_StaticSelectedStyle{
}
.menu_DynamicMenuStyle{
font-size:15px;
border-right: #B1B266 thin solid;
border-top: #B1B266 thin solid;
border-left: #B1B266 thin solid;
border-bottom: #B1B266 thin solid ;
z-index: 100;
width:100px;
}
.menu_DynamicMenuItemStyle{
width:200px;
/*HorizontalPadding="5px" VerticalPadding="2px"*/
}
.menu_DynamicSelectedStyle{
}
.menu_DynamicHoverStyle{
color:#FFFFFF;
background-color:#B1B266 ;
width:100px;
}

Gridview 套用 CSS

使用Visual Studio 直接拉gridview到畫面, 如果沒有再套上個css的話,真的是醜到暴, 這邊簡單做了一個css套上gridview,畫面好看多了
<asp:GridView ID="GridView1" runat="server" Width="800px" CssClass="fixedheader">
<RowStyle CssClass="gv_ItemCSSR" />
<HeaderStyle CssClass="gv_HeaderCSSM" />
<FooterStyle CssClass="gv_FooterCSS" />
<SelectedRowStyle CssClass ="gv_SelectedRowCSS" />
<Columns>
<asp:TemplateField HeaderText="選取" ShowHeader="False">
<ItemTemplate>
<asp:CheckBox ID="Chk" runat="server" Checked="True" />
</ItemTemplate>
</asp:TemplateField>
</Columns>
</asp:GridView>
/* gridview style*/
.fixedheader
{
left: 0px;
position: relative;
top: 0px;
font-size: 12px;
}
/* header 漸層*/
.gv_HeaderCSSN{
font-size: 14px;
height:20px;
font-weight :100; /* 不設定粗體的話 標題字會太粗 */
background-image: url(../Image_File/gv_bk01.gif);
}
/* header 條紋*/
.gv_HeaderCSSM{
font-size: 14px;
height:20px;
font-weight :100;
background-image: url(../Image_File/gv_bk02.gif);
}
/* header 深藍 字白字*/
.gv_HeaderCSSB
{
font-size: 14px;
height:20px;
font-weight :100;
color:#FFFFFF;
background-image: url(../Image_File/gv_bk03.gif);
}
.gv_ItemCSSG{
background-color: #EEFCF5;
height:15px;
font-size:9pt;
color:#000000;
}
.gv_ItemCSSB{
background-color: #EEEEFC;
height:15px;
font-size:9pt;
color:#000000;
}
.gv_ItemCSSR{
background-color: #FCEEEE;
height:15px;
font-size:9pt;
color:#000000;
}
.gv_SelectedRowCSS
{
background-color:#80FF80;
}
.gv_FooterCSS{
background-color: #1FBBBD;
color: white;
height:20px;
font-size:9pt;
}

jQuery plugin: Autocomplete

為了實現類似搜尋引擊自動完成的功能, 上網找有沒有現成的套件可以使用, http://bassistance.de/jquery-plugins/jquery-plugin-autocomplete/ jQuery提供不少好用的套件, 不過產生了一個問題, 如果我畫面上使用UpdatePanel則會沒有反應, 上網查了一下,原來是這個套件不支援非同步動作, 必須下載新版的jQuery並使用live綁定 原始:
$("#ctl00_ContentPlaceHolder1_TextBox8").autocomplete('Return_B.aspx?q=a',
{ 
delay: 200,
highlight: false,
multiple: true,
multipleSeparator: " ",
scroll: true,
scrollHeight: 300
});
改成:
$("#ctl00_ContentPlaceHolder1_TextBox8").live("keypress",function(){
$(this).autocomplete('Return_B.aspx?q=a',
{
delay: 200,
highlight: false,
multiple: true,
multipleSeparator: " ",
scroll: true,
scrollHeight: 300,
});
});
使用live()綁定之後雖然自動完成有反應, 不過每次自動搜尋出結果後, 又回來初始的搜尋結果, 只好暫時先把這個畫面的UpdatePanel拿掉, 再找辦法解決

2009年11月3日 星期二

IE8 與 MENU元件的BUG

引用自:http://blogs.msdn.com/giorgio/archive/2009/02/01/asp-net-menu-and-ie8-rendering-white-issue.aspx

加上<DynamicMenuStyle CssClass="IE8Fix" />

-------------------------------------
<asp:Menu ID="Menu1" runat="server" DataSourceID="SiteMapDataSource1">
<DynamicMenuStyle CssClass="IE8Fix" />
</asp:Menu>

.IE8Fix{
z-index: 100;
}

Web Service 介紹

Web Service主要是利用HTTP與XML進行網路上的資料交換,不論是不同的企業、公司內部網路等等。而一個完整的Web Service平台則是加上SOAP、WSDL、UDDI
UDDI (Universal Description Discovery and Integration) : 提供描述與搜尋與整合Web Service個標準。
WSDL (Web Service Description Language): 描述Web Services的Operation。
SOAP (Simple Object Access Protocol): 是一種通訊協定,雙方同時支援SOAP就可進行交談。
 
Client
                            UDDI

                            WSDL
(資料交換)
                            SOAP

                            XML

                            HTTP
Web Service提供者

2009年11月1日 星期日

Visual Studio 2005 中斷點無效問題

這算是IE8的bug吧,只要是先開了IE8,再開Visual Studio 2005開始偵錯時,
就會造成中斷點無法使用,解決方法:
開始 => 執行 => regedit
在HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
在Main目錄下,新增OWORD值取名為TabProcGrowth 給值0 就ok了
參考下面連結:
http://www.microsoft.com/windows/internet-explorer/beta/readiness/developers-existing.aspx#lcie

Older versions of the Visual Studio Debugger get confused by this and cannot figure out how to attach to the correct process. You can work around this by disabling the process growth feature of LCIE. Here's how:

1) Open RegEdit
2) Browse to HKEY_LOCALMACHINE -> SOFTWARE -> Microsoft -> Internet Explorer -> Main
3) Add a dword under this key called TabProcGrowth
4) Set TabProcGrowth to 0

Since you are running on Windows Server 2003, this is all you should need to do. If you run into the same problem on Vista or newer, you will also need to turn off protected mode.

2009年10月30日 星期五

太實用的文章,有使用匯入excel功能一定要看。匯入Excel所有遇到的情況!!!!

引用自:http://blog.miniasp.com/post/2008/08/How-to-read-Excel-file-using-OleDb-correctly.aspx

當發現利用oledb匯入excel到資料庫發生某些欄位無法匯入(空白)或某些值進不去時(字串)


"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\\Excel.xls;Extended Properties=\"Excel 8.0;HDR=Yes;IMEX=1\";

1.Excel 8.0 : Excel 8.0 是 Office 97 的 Excel 格式,這個格式從 Excel 97 ~ Excel 2003 都相容
2.HDR ( HeaDer Row ): 若指定值為 Yes,代表 Excel 檔中的工作表第一列是欄位名稱
若指定值為 No,代表 Excel 檔中的工作表第一列就是資料了,沒有欄位名稱
3.IMEX ( IMport EXport mode ): IMEX 有三種模式,分別讀寫行為也不同,容後再述:
0 is Export mode
1 is Import mode
2 is Linked mode (full update capabilities)
當 IMEX=0 時為「匯出模式」,這個模式開啟的 Excel 檔案只能用來做「寫入」用途。
當 IMEX=1 時為「匯入模式」,這個模式開啟的 Excel 檔案只能用來做「讀取」用途。
當 IMEX=2 時為「連結模式」,這個模式開啟的 Excel 檔案可同時支援「讀取」與「寫入」用途。
所以當我們要開發 Excel 檔案匯入功能時,正確的 IMEX 設定應該是 1 才對,不過就算設定 IMEX=1 還不夠,還有一些需要注意的地方!

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Jet\3.5\Engines\Excel 位置,這裡有兩個非常重要的設定:
1. ImportMixedTypes
在 Excel 機碼中 ImportMixedTypes 的預設值為 Text,代表當你讀入 Excel 檔案時若每一列的資料格式不一致的話,
Jet Engine 預設會將欄位的資料格式自動轉成文字(Text)格式!
2. TypeGuessRows
在 Excel 機碼中 TypeGuessRows 的預設值為 8,代表當你讀入 Excel 檔案時若每一列的資料格式不一致的話,Jet Engine 會先讀取前 8 列的資料,用已判斷之後的資料格式是否固定。假設若前 8 列的資料都是「日期」格式,那麼在第 8 列之後的資料 Jet Engine 會自動解析成「日期」格式,但只要遇到有的資料不是「日期」格式時,就會回傳 Null 給 Jet Engine。要解決這個問題也很容易,只要將 Excel 機碼中 TypeGuessRows 的值改成 0 即可,只是若你匯入的資料量蠻大的話可能會影響資料讀取時的效能,因為 Jet Engine 會將所有資料讀完才會判斷出每個欄位應該用什麼資料格式。

修改完後,就不會有Datatable讀excel讀不到(沒設定IMEX = 1),
或是只決定前8行資料的格式就判定Datatable欄位的格式(修改TypeGuessRows值為0)

2009年10月29日 星期四

解決 DIV 包 DIV 超出範圍問題

<style type="text/css">
#mastercontent { position:relative; width:100%;height :100%;border-right: #ff3300 thin solid; border-top: #ff3300 thin solid; border-left: #ff3300 thin solid; border-bottom:#ff3300 thin solid;}
#primary { position:absolute; margin-left: 200px; width:192px; border-right: #00cc66 thin solid; border-top: #00cc66 thin solid; border-left: #00cc66 thin solid; border-bottom:#00cc66 thin solid;}
#secondary { position:absolute; width:192px; border-right: #0099cc thin solid; border-top: #0099cc thin solid; border-left: #0099cc thin solid; border-bottom:#0099cc thin solid;}
</style>
<div  id = "mastercontent">
<div id = "primary">
<br/><br/><br/><br/>
</div>
<div id = "secondary">
<br/><br/><br/><br/><br/><br/><br/><br/><br/>
</div>
</div>
出現了上圖的問題,又不想設定父DIV的高度(不同解析度會出現捲軸) 如果加上下面script即可解決
<script type="text/javascript">
var h = document.documentElement.clientHeight ;  /*先抓畫面上可視範圍的高度*/
var obj1= document.getElementById ("mastercontent");
var obj2= document.getElementById ("primary");
var obj3= document.getElementById ("secondary");
obj1.style.height = h -60; /*設定div高度*/
obj2.style.height = h -66;
obj3.style.height = h -66;
</script>

2009年10月21日 星期三

DropDownlist 內可打字


前陣子有個需求希望web裡的 DropDownlist像Excel一樣可以打字
上網搜尋了一下 終於有解
不過這不是真正的元件
雖然我已經把他寫成一個WebUserControl可以使用
他的架構是這樣:

2009年10月16日 星期五

迴圈處理畫面上的元件

當畫面上有多個元件 程式要同時塞值進去時,就可使用迴圈控制 不需要指定個別元件給值 '畫面上有4個TextBox
Dim txt() As String = {"TextBox1", "TextBox2", "TextBox3", "TextBox4"}
Dim txt1(txt.Length) As TextBox
For i As Integer = 0 To txt.Length - 1
txt1(i) = form1.FindControl(txt(i))
txt1(i).Text = i
Next

2009年10月14日 星期三

Store Procedures with MSSQL and ASP.NET

(MSSQL)
CREATE PROCEDURE [dbo].[test] --新增預存程序test並給一輸入參數
@tool_no varchar(50)
AS
   SELECT  [Tool_No],[Serial_No],[Tool_Revision]
   FROM [ACF_Tooling].[dbo].[Main]
   WHERE Tool_No = @tool_no
GO
--exec test 'AAA'; --執行預存程式並給定輸入值
(ASP.NET)
Dim ToolingConnectionString As New ConnectionString
Dim conn As New SqlConnection(ToolingConnectionString.ToolingConnectionString)
Dim sqlcmd As New SqlCommand("test", conn)
Dim dt As New DataTable
sqlcmd.CommandType = CommandType.StoredProcedure
sqlcmd.Parameters.AddWithValue("@tool_no", TextBox1.Text)
conn.Open()
dt.Load(sqlcmd.ExecuteReader)
conn.Close()
If dt.Rows.Count > 0 Then
   GridView1.DataSource = dt
   GridView1.DataBind()
End If

2009年10月13日 星期二

Silverlight 使用心得

最近由於公司內部要自辦訓練課程,
腦子突然想到Silverlight這套工具,
畢竟這也算是比較新的技術可以跟同事分享,
並且對一直想學Silverlight的我,順便也有學習的機會。
微軟在2007年7月推出Silverlight 1.0,短短的2年內已經到3.0目前
1.0的版本我有去嘗試,只能以重創形容...
一直到現在使用visual studio 2008(sp1) + Silverlight 2.0 + Expression Blend 2.0
總算玩出個結果,
只能說微軟剛推出的東西,真的不要輕易嘗試。
或許1.0的相容性及支援太差,當我使用2.0發現很好上手。
不過第一次使用還是吃了不少苦頭。
公司裡面目前還是使用Visual Studio 2005 而為了使用Silverlight 2.0 去借了VS2008,
還好公司有這軟體,不過是中文版的,
上網搜尋了一下Silverlight的環境安裝,
下載silverlight_sdk,結果失敗(1)...
原來是要相同語言,因為我的Visual Studio 2008是繁體中文版,
好不容易安裝好後,開始使用時,發現沒有網路上看到的Silverlight樣版,
原來還要安裝Silverlight_Tools,
結果失敗(2)...
原因是Silverlight_Tool線上安裝,結果被公司的proxy擋住。
總算安裝好Silverlight_Tools也看到了Silverlight樣版,
這時當然想使用一下Expression Blend 這套軟體,看人家介紹可以VS跟Blend互動,
好像不錯玩,結果失敗(3)...
原因是我裝的是Expression Blend 1.0,必須要相同版本才行,
還好公司剛好有Expression Blend 2.0。
當我在VS上在XAML檔上按右鍵,看到了"於Expression Blend中開啟",
結果失敗(4)...
原因查了老半天,原來Blend也要裝sp1,
安裝完後,測試的結果還算滿意,
其實這是一套很好的技術,但對於比較沒網頁基礎的人有點難度,
網路上的資源是不少,不過不是原文的,就是那幾篇文章(高手寫的文章對入門的新手有點難度),
市面上的書也就那幾本,大部分整本都寫code,
突然想到以前有一本書介紹說,為什麼很多書用的範例都打到記事本上
難道真的有人用記事本開發ASP.NET?
真搞不懂那麼多人連環境都架不起來了,市面上要找這樣的入門書好難。

2009年9月30日 星期三

避免讀入excel資料變空白

Provider=Microsoft.Jet.OLEDB.4.0;Data Source=EXCEL文件檔名;Extended Properties='Excel 8.0;HDR=YES;IMEX=1'

Text內預設文字...

<input id="Text1" onfocus="javascript:if( this.value=='請輸入搜尋字串...')this.value=''" onblur="javascript:if( this.value=='' )this.value='請輸入搜尋字串...'" value="請輸入搜尋字串..."  type="text"/>

2009年9月21日 星期一

SQL SERVER 日期轉換

取自~ http://blog.miniasp.com/post/2008/02/Use-CONVERT-function-to-deal-with-SQL-Server-Datetime.aspx
輸出格式:2008-02-27 00:25:13
SELECT CONVERT(char(19), getdate(), 120)

輸出格式:2008-02-27
SELECT CONVERT(char(10), getdate(), 20)

輸出格式:2008.02.27
SELECT CONVERT(char(10), getdate(), 102)

輸出格式:08.02.27
SELECT CONVERT(char(8), getdate(), 2)

輸出格式:2008/02/27
SELECT CONVERT(char(10), getdate(), 111)

輸出格式:08/02/27
SELECT CONVERT(char(8), getdate(), 11)

輸出格式:20080227
SELECT CONVERT(char(8), getdate(), 112)

輸出格式:080227
SELECT CONVERT(char(6), getdate(), 12)

window.showModalDialog範例~

window.showModalDialog

 
Mfg_Steel.aspx
< input id="Button2" onclick="test1();" value="加入工時" type="button" >
--------------------------------------------------------
<script language="javascript">
function test1( ){
var obj=document.getElementById("GridView2$ctl02$txtJSM1");
window.showModalDialog("Mfg_Steel_2.htm",obj,"dialogWidth=800px;dialogHeight=800px");
}
</script>
☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆☆
Mfg_Steel_2.htm
56<input id="Radio3" onclick="radiovalue2(value);" value="56" type="radio" name="SFB">
112<input id="Radio10" onclick="radiovalue3(value);" value="112" type="radio" name="SFD">
--------------------------------------------------------
<input id="Button1" onclick="sum1();" value="加總" type="button">
<input id="Button2" onclick="testb();" value="送出" type="button">
--------------------------------------------------------
<script language="javascript">
objtxt1 = document.getElementById("Text1") ;
objtxt2 = document.getElementById("Text2") ;
objtxt3 = document.getElementById("Text3") ;
function radiovalue2(value2){
sfb = value2;
objtxt2.value = sfb;
}
function radiovalue3(value3){
sfd = value3;
objtxt3.value = sfd;
}
function sum1( ){
objtxt1.value = parseInt(objtxt2.value) + parseInt(objtxt3.value)
}
function testb( ){
var objb= window.dialogArguments;
objb.value=objtxt1.value;
window.close( );
}
</script>

網路提供者都不接受指定的路徑

系統管理工具→服務→Workstation 啟動
系統管理工具→服務→Computer Browser 啟動
系統管理工具→服務→Routing and Remote Access 啟動

Usercontrol與Page傳值

Login_tmp1 : Usercontrol名稱
TextBox3 : Usercontrol內的元件
logintmp_chk : Page內宣告的TextBox
logintmp_chk = CType(Login_tmp1.FindControl("TextBox3"), TextBox)

網頁預設按Enter時...

為了不讓網頁按Enter時按到預設的Button
設定按Enter時按鍵頭"上"
就不會產生畫面的PostBack了

另外可用.net 2005 的DefaultButton設定要預設的Button

ModalPopupExtender


BackgroundCssClass="modalBackground"
加入這樣式才會有跳出的感覺
搞老半天...

Oracle 日期欄位轉字串的方法

TO_CHAR(, '')
範例:
SELECT TO_CHAR(b, 'YYYY/MM/DD') AS b FROM x;
Oracle 字串轉日期欄位的方法 ( Oracle 寫入日期的方法 )
TO_DATE(, '')
範例:
TO_DATE('2006/8/29', 'YYYY/MM/DD')

轉自
http://infolab.stanford.edu/~ullman/fcdb/oracle/or-time.html

Oracle 設定流水號

進入SQL-Plus後
--------------宣告concession
CREATE SEQUENCE concession_sequence
INCREMENT BY 1
START WITH 1
NOMAXVALUE
NOCYCLE
CACHE 10;
--------------使用
concession_sequence.nextval;
--------------刪除sequence
DROP SEQUENCE concession_sequence;

Oracle資料庫問題,無法從Client連到Server的Oracle Client

Client端電腦透過公司的Server端電腦連至SAP資料庫
怎麼樣都不行連(重裝Oracle Client也不行)
後來改了一下Server端Oracle的權限設定
在Oracle的安裝目錄下 C:\oracle\ora92
將ora92的權限中的Authenticated Users加入完全控制(預設只有讀取及執行、清單資料夾內容、讀取)
即可解決

.net 一般性問題,重新註冊 framework

系統上必須先有IIS再裝.net才不會出現問題
假使不小心移除IIS 則再註冊一次.net即可
%WinDir%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -i

跳出警告視窗~AJAX

Sys.WebForms.PageRequestManagerServerErrorException:An unknown error occurred while processing the request on the server. The status code returned from the server was :500
AJAX將錯誤隱藏住 要先移掉AJAX元件

伺服器應用程式無法使用 .net 2005

無法執行要求,因為無法建立 App-Domain。錯誤: 0x80070005 存取被拒。
加入NETWORK SERVICE的權限即可

WebChart

好用的統計圖工具~ http://www.carlosag.net/Tools/WebChart/Default.aspx 下載WebChart.dll後 到工具箱新增/移除項目 新增.NET Framework元件
Imports WebChart
Private Sub CreateChart()
'ChartControl1.YCustomStart = Session("ds_chart").Rows(0).Item(7) - 0.5 '定義Y軸的起始點
'ChartControl1.YCustomEnd = Session("ds_chart").Rows(0).Item(7) + 0.5 '定義Y軸的結束點
ChartControl1.ChartTitle.Text = "50筆最新資料" '定義Title名稱
Dim chart As LineChart = New LineChart
chart.Line.Color = Color.Green 'Line的顏色
chart.Legend = "值" '代表Line的名稱
Dim chart1 As LineChart = New LineChart
chart1.Line.Color = Color.Blue
chart1.Legend = "實測尺碼"
Dim chart2 As LineChart = New LineChart
chart2.Line.Color = Color.Red
chart2.Legend = "差值"
For Each row As DataRow In Session("ds_chart").Rows '讀Dateset的值
chart.Data.Add(New ChartPoint(row("值").ToString, CType(row("值"), Integer)))
chart1.Data.Add(New ChartPoint(row("實測尺碼").ToString, CType(row("實測尺碼"), Integer)))
chart2.Data.Add(New ChartPoint(row("差值").ToString, CType(row("差值"), Integer)))
Next
ChartControl1.Charts.Add(chart)
ChartControl1.Charts.Add(chart1)
ChartControl1.Charts.Add(chart2)
ChartControl1.RedrawChart()
End Sub

Google Chart API

Google所提供的一套API http://code.google.com/apis/chart/ 使用方式直接在網址後面接參數
Dim strLink As String = "http://chart.apis.google.com/chart?"
Dim strCht As String = "cht=lxy"
Dim strChs As String = "&chs=300x200"
Dim strChd As String = "&chd=t:" & "0,30,60,70,90,95,100" & "|" & Session("ds_temp")
Dim strChxt As String = "&chxt=x&chxl=0:|0|10|20|30|40|50|"
Response.Redirect(strLink & strCht & strChs & strChd & strChxt)

cht -- Chart type
chs -- Chart sizte
chd -- Chart data
chl -- Chart Label
chxt -- top x-axis
chxl -- the pipe character (|) is not required after the last parameter.

撈資料庫值顯示對照圖至表格

Dim sqlstr As String
Dim dr As SqlClient.SqlDataReader
sqlstr = "SELECT TDM_NAME FROM TN_C_TYPE"
Dim cmd As New SqlClient.SqlCommand(sqlstr, SqlConnection1)
Dim row As HtmlTableRow
Dim cell_Photo As HtmlTableCell
Dim cell_Text As HtmlTableCell
SqlConnection1.Open()
dr = cmd.ExecuteReader
While dr.Read
row = New HtmlTableRow
For i As Integer = 0 To dr.FieldCount - 1
cell_Text = New HtmlTableCell
cell_Photo = New HtmlTableCell
cell_Text.InnerText = dr.Item(i)
//dr.Item(0) ..資料庫第一欄 dr.Item(1) ..資料庫第二欄 cell_Photo.InnerHtml = " < img src='/PIC/Cutter_Pic/" & dr.Item(i) & ".jpg' align='center' onerror=this.style.display='none' src=''>" row.Cells.Add(cell_Text) row.Cells.Add(cell_Photo) Next Table1.Rows.Add(row) End While dr.Close() SqlConnection1.Close()

ASP.NET 編輯 excel 檔

Dim cn As New Data.OleDb.OleDbConnection
Dim da As Data.OleDb.OleDbDataAdapter
Dim dt As New DataTable
Dim sqlstr As String
Dim oComm As SqlCommand
cn.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source= " &  Server.MapPath("檔名.XLS") & "; Extended Properties=Excel 8.0;"
For i As Integer = 1 To 100    'excel內有100筆資料
cn.Open()
da = New OleDb.OleDbDataAdapter("select * from [Data$]", cn)  'Data=>"Booksheet"
da.Fill(dt)
sqlstr = sqlstr + "INSERT INTO SPC_Table (零件件號) VALUES (dt.Rows(i + 4).Item(1)"  'excel內每筆資料為Row
Dim ds As New DataSet
SqlConnection1.Open()
oComm = New SqlCommand(sqlstr, SqlConnection1)
oComm.ExecuteNonQuery()
SqlConnection1.Close()
cn.Close()
Next

Excel檔匯入Oracle

1. 將excel轉存為.csv
2. 建立.ctl檔
檔案內容----
load data
infile "c:\SPC_Table.csv"(資料檔名稱與路徑)
badfile "bad.log"
discardfile "discard.log"
into table SPC_TABLE(Oracle裡的Table)
fields terminated by ',' optionally enclosed by '"'(原始資料以,區格)
trailing nullcols (欄位內容)
( 零件件號
, OP
, 工令
, 日期
, 序號
, 圖號
, 值
, 操作人員
)
3. 在命令提示字元下> sqlldr userid=帳號/密碼 control=C:\SPC_Table.ctl

Javascript控制Html與Server端元件

//控制Html元件,Hidden_Btn為元件名稱
function Add( ){
if (confirm("是否確定要新增?")) {
document.getElementById("Hidden_Btn").click();
}
}
//控制Server端元件,New_Button為元件名稱
function Add( ){
if (confirm("是否確定要新增?")) {
return __doPostBack('New_Button','')
}
}

Javascript傳值

//Html內,傳變數Para_Link
if (confirm("是否確定要新增?")) {
location.href="Put_In_Storage_Cutter_Link.aspx?Para_Link=Add";
}
// 程式內 ,接收變數 Para_Link
Para_Link = Request("Para_Link")
If Para_Link = "Add" Then
Message_Label.Text = "javascript"
End If

Cursor用法 ~MS SQL

USE aeftool_Data
--定義一個cursor 來自指定資料表內容
DECLARE 測試用_Cursor Cursor FOR
SELECT CN_T_KEY1
FROM 測試用
--開啟cursor
OPEN 測試用_Cursor
--定義cursor裡要取出的物件
DECLARE @KEY VARCHAR(50)
DECLARE @COUNT INT
--進入cursor
Fetch NEXT FROM 測試用_Cursor INTO @KEY
--當陳述式失敗,或資料列超出結果集時停止迴圈
While (@@FETCH_STATUS <> -1)
BEGIN
SELECT @COUNT=COUNT(*)
FROM SMARTEAM.TN_LINK_KNIFE LINK
WHERE LINK.CN_T_KEY1 = @KEY
IF @COUNT>0
PRINT 'TEST'
--再到下個指標去
Fetch NEXT FROM 測試用_Cursor INTO @KEY
END
--關閉cursor
CLOSE 測試用_Cursor
--釋放cursor
DEALLOCATE 測試用_Cursor
GO