2010-12-28

IMPORT EXCEL 2007 INTO SQL SERVER 2005

Perfrom following steps to Import Excel 2007 Sheet into SQL Server 2005.
Step 1: Select Destination Database where you would like to Import Excel 2007 Sheet.
Right click database > Tasks > Select Import data… as shown in following figure.
Step 2: Select “Microsoft Office 12.0 Access Database Engine OLE DB Provider" from data source selection drop down. Click on “Properties…" button as shown in figure.
Step 3: Properties dialog box appears.
Click on “Connection Tab" and Enter Excel 2007 file path in Data source text box.
Step 4: Click on “All Tab
Select “Extended Properties" from given edit values and click on “Edit Value…" button
Step 5: Edit value dialog box appears.
Enter “Excel 12.0" in Property value textbox and click OK button
Step 6: Press Test Connection button to make sure everything is working good.
Finally press OK button.
After that you need to follow usual procedure to import excel sheet data into sql server. i.e. You need to click next and follow wizard instructions.

2010-11-12

Restore to another database from DB backup file

RESTORE DATABASE [MyDB2]
FROM DISK = N’D:\Backup\MyDB\MyDB_20080205.bak’
WITH FILE = 1,
MOVE N’MyDB’ TO N’E:\DB\MyDB2.mdf’,
MOVE N’MyDB_log’ TO N’E:\DB\MyDB2.ldf’,
KEEP_REPLICATION, NOUNLOAD, REPLACE, STATS = 10

Copy and insert rows with identity column

SET IDENTITY_INSERT MakeMOney.dbo.ListingHistory ON   <–要設定
insert into MakeMOney.dbo.ListingHistory (ListingItemID,PackageID, ProductID, eBayItemID, Quantity, Sold, Price, HandlingFee, ListingFee, Title, StartTime, EndTime, ItemURL, Duration, Status,                       WarehouseID, HitCount, Lister, LastReviseDate)select  ListingItemID,PackageID, ProductID, eBayItemID, Quantity, Sold, Price, HandlingFee, ListingFee, Title, StartTime, EndTime, ItemURL, Duration, Status,                       WarehouseID, HitCount, Lister, LastReviseDate from ListingHistory where Status=’Active’ and year(StartTime)<=2008
↑insert時要指定欄位

2010-10-19

Facebook 分享連結

http://www.facebook.com/share.php?u=分享網址&t=網頁標題
但是實際上連過去以後 FB會自動從分享網址搜尋 他要的訊息,不一定會顯示你指定的標題
所以你必須在頁面上做一些語法標示,可以出現標題、文案和圖示,用以下的語法可以做到
讓FB抓到你要的推荐資料,記得這些是加在</head>前面
<meta name="title" content="網頁標題會顯示粗體" />
<meta name="description" content="網頁說明文案" />
<link rel="image_src" type="image/jpeg" href="要顯示的圖檔網址.jpg" />
圖片的大小寬度是100px內,在大的話,FB會縮圖,圖片就可能會變形。
 
效果會像這樣
如果要多張圖的話
建議另外寫不同的方式來讓FB讀到圖片
就是將img圖片寫在<li></li>標籤裏面,效果是比較好的,且圖片要用全網址http://開頭,不要只用xxx.jpg
對於其他類似的像murmur.tw也可以抓的到,比較通用。
全Flash的話可以圖片把它定義在一個div區塊設隱藏css語法display:none;
圖片一定要在flash前面

2010-10-10

排程壓縮

STEP1:您的電腦 要 有安裝 過 WINRAR
STEP 2:請 將 \Program Files\WinRAR\RAR.exe 檔 複製 到 一個 子目錄中,例如 C:\TEST
STEP 3: 建立一個 批次 檔案, 內容 如下例子 C:\test\RAR.exe a -r -ep -m3 -T -agYYYYMMDD D:\Database_Backup\.zip D:\Database_source\*.*
== 說明 : 此 指令 會將 D:\Database_source 下的 檔案 全部 壓縮 到 D:\Database_Backup 下 存成 yyymmdd.zip 的檔案
STEP 4: 利用 排程 來自動 執行 此 批次
== 可 切換 到 C:\TEST 資料 夾下 執行 RAR.EXE 查看 詳細 指令 內容
==
a : 新增壓縮檔
-R – 遞迴子資料夾:全部子資料夾的檔案將會一併處理
-EP – 排除檔名的路徑:檔案在加入壓縮檔案時不會包含路徑資訊
-m<n> – 設定壓縮方法:
-m0 僅儲存 加入檔案到壓縮檔但是不壓縮
-m1 最快 最快速的方法 (最低的壓縮比)
-m2 快速 快速壓縮法
-m3 標準 標準 (預設) 壓縮方法
-m4 較好 較好的壓縮方法 (較高的壓縮比)
-m5 最佳 最佳的壓縮方法 (最高壓縮比但是速度也最慢)
-T – 壓縮後測試檔案
-AG[格式] – 使用目前的日期時間產生壓縮檔名:以格式 [YYYYMMDDHHMMSS] 附加目前日期字串
Y 年
M 月
MMM 純文字式的月份 (Jan,Feb,等)
W 純文字星期 (星期以星期一開始)
A 數字星期 (星期一為 1,星期日為 7)
D 日(月)
E 日(年)
H 時
M 分 (如果接續在時後面,則視為分看待)
S 秒
N 壓縮檔編號。WinRAR 對既有的檔案尋找賦予的名稱,如果找到,則增加壓縮檔編號直到檔名唯一為止。
D:\Database_Backup\.ZIP 把檔案壓縮到這個地方,檔名 YYYYMMDD.ZIP (例如:20070125.ZIP)
D:\Database_SOURCE\*.* 壓縮這個目錄下的所有檔案

排程 上傳FTP

傳輸單個檔案
一、先用記事本編輯一個檔案(ftp.txt)
open ip_address(hostname) /*要連接的ftp*/
userid /*登入id*/
password /*登入pw*/
binary /*以二進制傳送文件,可選項*/
cd remote_directory_path /*ftp上的資料夾路徑*/
put local_filename remote_filename /*將local端的檔案上傳到ftp*/(單一檔案)
get remote_filename local_filename /*將ftp上的檔案下載到local端*/(單一檔案)
bye /*離開ftp*/
二、執行
<Ⅰ>直接在command mode下輸入ftp -s:ftp.txt
<Ⅱ>製成一個批次檔(bat),內容為 ftp -s:ftp.txt,然後排入工作排程!!即可自動執行
ps:批次檔跟txt檔需在同一個資料夾,批次檔命名可以特別些,勿與系統批次檔同名
傳輸多個檔案
一、先用記事本編輯一個檔案(ftp.txt)
open ip_address(hostname) /*要連接的ftp*/
userid /*登入id*/
password /*登入pw*/
prompt /*忽略對話窗,預設回答on*/
cd remote_directory_path /*ftp上的資料夾路徑*/
mput local_directory_pathfile_name /*將local端路徑資料夾的檔案上傳到ftp*/(多個檔案)
mget *.* /*將ftp資料夾路徑的檔案下載到ftp.txt放置的資料夾*/
bye /*離開ftp*/
二、執行
<Ⅰ>直接在command mode下輸入ftp -s:ftp.txt
<Ⅱ>製成一個批次檔(bat),內容為 ftp -s:ftp.txt,然後排入工作排程!!即可自動執行
ps:批次檔跟txt檔需在同一個資料夾,批次檔命名可以特別些,勿與系統批次檔同名

2010-08-30

PagerTemplate of GridView

當要動態新增PagerTemplate內的控制項時, 必須宣告在GridView的RowCreated事件中, 不能在RowDataBound中做操作

2010-08-06

GridView export to Excel

   public static void GVExportExcel(HttpContext c, GridView GV,string FileName )
    {
        System.IO.StringWriter tw = new System.IO.StringWriter();
        HtmlTextWriter hw = new HtmlTextWriter(tw);       
        c.Response.ContentType = "application/x-excel";
        c.Response.AddHeader("content-disposition", "attachment;filename=" + HttpUtility.UrlEncode(FileName + ".xls"));
        GV.RenderControl(hw);
        c.Response.Write(tw.ToString());
        c.Response.End();
    }
Notification :
1. If page is under MasterPage, it requires to add EnableEventValidation="false" inside <%@ Page %>
2. If page is in inside UpdatePanel, it requires to register postback control. ScriptManager.GetCurrent(Page).RegisterPostBackControl(btnExport);
3. Following override function is required inside page.
    public override void VerifyRenderingInServerForm(Control control)
    {
        //For GridView export Excel
        /* Confirms that an HtmlForm control is rendered for the specified ASP.NET
        server control at run time. */
    }

2010-07-11

MIME subject format

 =?charset?encoding?encoded text?=
 
EX:
 =?big5?B?YXR0YWNobWVudCB0ZXN0LCCkpKTltPq41Q==?=
 
?B? = Binary, use base64 to decode
?Q? = Quoted Printed

2010-07-01

開關機執行指令碼

  1. 先從開始 » 執行… 輸入 gpedit.msc 然後按下 Enter,開啟群組原則。
  2. 然後找到本機電腦 原則 » 電腦設定 » Windows 設定 » 指令碼 – (啟動/關機)
    1. 接著就可以在右邊的啟動和關機中點兩下來設定指令碼囉。這邊舉的例子,是假設 RAMDisk 為 B:、備份的檔案存至 D:\RAMDisk 中。如果有不一樣,請自行變通一下。
    2. 啟動的指令碼名稱:
      cmd
    • 啟動的指令碼參數:
      /C xcopy /C /E /Y D:\\RAMDisk B:
    • 關機的指令碼名稱:
      cmd
    • 關機的指令碼參數:
      /C xcopy /C /E /Y B: D:\\RAMDisk
    1. 如此設定就大功告成囉!重開機實際測試看看吧!

    2010-04-06

    Using the LINQ to SQL Debug Visualizer

    One of the nice development features that LINQ to SQL supports is the ability to use a "debug visualizer" to hover over a LINQ expression while in the VS 2008 debugger and inspect the raw SQL that the ORM will ultimately execute at runtime when evaluating the LINQ query expression.
    For example, assume we write the below LINQ query expression code against a set of data model classes:
    We could then use the VS 2008 debugger to hover over the "products" variable after the query expression has been assigned:
    And if we click the small magnifying glass in the expression above, we can launch the LINQ to SQL debug visualizer to inspect the raw SQL that the ORM will execute based on that LINQ query:
    If you click the "Execute" button, you can even test out the SQL query and see the raw returned results that will be returned from the database:
    This obviously makes it super easy to see precisely what SQL query logic LINQ to SQL ORM is doing for you. 
    You can learn even more about how all this works by reading the Part 3: Querying our Database segment in my LINQ to SQL series above.

    HOW TO INSTALL THE LINQ TO SQL DEBUG VISUALIZER

    The LINQ to SQL Debug Visualizer isn’t built-in to VS 2008 – instead it is an add-in that you need to download to use.  You can download a copy of it here.
    The download contains both a binary .dll assembly version of the visualizer (within the \bin\debug directory below), as well as all of the source code for the visualizer:
    To install the LINQ to SQL debug visualizer, follow the below steps:
    1) Shutdown all running versions of Visual Studio 2008
    2) Copy the SqlServerQueryVisualizer.dll assembly from the \bin\debug\directory in the .zip download above into your local \Program Files\Microsoft Visual Studio 9.0\Common7\Packages\Debugger\Visualizers\ directory:
    3) Start up Visual Studio 2008 again.  Now when you use the debugger with LINQ to SQL you should be able to hover over LINQ query expressions and inspect their raw SQL (no extra registration is required).

    2010-02-24

    Listen windows messages in controls

    Public Class MyTextBox
         Inherits TextBox
         Private WM_KEYUP As Integer = &H101
              If m.Msg = WM_KEYUP Then
         Protected Overrides Sub WndProc(ByRef m As System.Windows.Forms.Message)
                   Return 'ignore the keyup
              End If
              MyBase.WndProc(m)
         End Sub 'WndProc
    End Class 'MyTextBox

    2010-01-22

    Some Registry Info.

    Get media player version

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MediaPlayer\PlayerUpgrade\PlayerVersion


    Get Excel version

    Dim key As RegistryKey = Registry.ClassesRoot.OpenSubKey(“CLSID\{00024500-0000-0000-C000-000000000046}\ProgID")
    If IsNothing(key) Then Return ConStr
    Select Case key.GetValue(“")
    Case “Excel.Application.14″
    ConStr = “provider=Microsoft.ACE.OLEDB.12.0;data source=" & TheFileName & “;Extended Properties=Excel 12.0;"
    Case Else ‘"Excel.Application.11″
    ConStr = “provider=Microsoft.Jet.OLEDB.4.0;data source=" & TheFileName & “;Extended Properties=Excel 8.0;"
    End Select

    Modify Remote Desktop Listening PORT

    HKEY_LOCAL_MACHINE\System\CurrentControlSet\Control\TerminalServer\WinStations\RDP-Tcp\PortNumber

    2010-01-01

    How to include google adsense in your facebook application

    Posted by David Heward on February 11th, 2009
    Adding google adsense to a facebook application has been a rather taboo subject for the last few years that you have been able to develop applications fully. It is now however becoming easier. Although still a taboo subject as to whether google will allow its ads to be displayed using an iframe and wether displaying google ads in this manor violates googles terms of service. Using these sort of ads on your application may run you the risk of having your adsense account closed or suspended at any time, but so far so good for those that i know.
    My eCPM with Google varies from $ 0.50 – 0.75 (eCPM). That is reliable, since it’s been like that over a 6 month period.
    Google does require you to have a website you own, that it will find acceptable to put Google ads on, that it is Google bots can view it, and it adheres to their policies so only having a Facebook App won’t work for getting you in the door.
    You need to have something more than a Facebook App like your company or personal website to point Google at registration, then you are free to use the ads anywhere you want, including your Facebook App.
    If you don’t, write up some basic html/php based website with a few pages, and it should be enough to keep Google happy.
    Warning: 
    You run the risk of having the account suspended potentially, since Gooogle Adsense TOS does not permit the use of iframes to display their ads. so you take my advice at your own risk.
    I recommend at most 2 ads per page.
    Now to the ‘how to do it’ part:

    Step 1:

    Your first step is to create a page called ‘google_code.htm’ – This is going to be the actual ads page, you will need to add some keywords, targeted references and at the very least a paragraphs worth of content and of course your google ad box code itself.
    An example of this can be seen below.
    01.<body style="background: #000000;">
    02.  
    03.<div style="position: relative; top: -5px; left: -5px;">
    04.  
    05.<script type="text/javascript"><!--
    06.google_ad_client = "pub-*****************";
    07./* FB-Header Ad - 728x90 */
    08.google_ad_slot = "*************";
    09.google_ad_width = 728;
    10.google_ad_height = 90;
    11.//-->
    12.</script>
    13.<script type="text/javascript"
    15.  
    16./pagead/show_ads.js">
    17.</script>
    18.  
    19.</div>
    20.  
    21.<br />
    22.<br />
    23.<br />
    24.<br />
    25.  
    26.<p>
    27.  
    28.<b>keywords</b>
    29.<i>keywords</i>
    30.Content - Atleast a Paragraph
    31.<b>keywords</b>
    32.<i>keywords</i>
    33.  
    34.</p>
    35.  
    36.<h1>keywords</h1>
    37.<h2>keywords</h2>
    38.<h3>keywords</h3>
    39.<h4>keywords</h4>
    40.<h5>keywords</h5>
    41.<b>keywords</b>
    42.</body>

    Step 2: The middle page

    The next step is to create another page called ‘google_frame.htm’ this page has a frame which displays the google_code.htm actual ads page. (I think its a good idea to put some more keywords here too).
    01.<html>
    02.  
    03.<head></head>
    04.  
    05.<frameset border="0" frameborder="0" framespacing="0" rows="100%,*">
    06.<frame src="google_code.htm" noresize scrolling="no">
    07.</frameset>
    08.  
    09.<br />
    10.<br />
    11.<br />
    12.<br />
    13.  
    14.<p>
    15.  
    16.<b>keywords</b>
    17.<i>keywords</i>
    18.Content - Atleast a Paragraph
    19.<b>keywords</b>
    20.<i>keywords</i>
    21.  
    22.</p>
    23.  
    24.<h1>keywords</h1>
    25.<h2>keywords</h2>
    26.<h3>keywords</h3>
    27.<h4>keywords</h4>
    28.<h5>keywords</h5>
    29.<b>keywords</b>
    30.  
    31.</html>

    Now for the final step

    Okay now on your canvas page or on any page that you use for your facebook application you can now simply include the code below.
    1.<fb:iframe src=*server address* /includes/google_frame.htm
    2.id="games-header" name="games-header"
    3.marginwidth="10" marginheight="10" scrolling="no" frameborder="0"
    4.height="105" width="740" />
    Now you should have your very own targeted google ads in your facebook application. It may also be good to make some pages that google can crawl from your google_code.htm etc pages.
    Make links to some other pages which will contain some content this will help the relevance of your ads.