2008年3月27日 星期四

工作管理員TAB不見如何處理

把滑鼠游標移到工作管理員的視窗邊框上-->按兩下就行了(double-click),工作管理員的功能表就會出現,恢復到傳統外觀。

2008年3月21日 星期五

VB.NET 發信

Dim mailmsg As New System.Net.Mail.MailMessage
mailmsg.To.Add(New System.Net.Mail.MailAddress("maxx31@xx.com.tw", "助理"))
mailmsg.Bcc.Add(New System.Net.Mail.MailAddress("rowxx@xx.com.tw", "電腦"))
Dim smtp As New System.Net.Mail.SmtpClient
smtp.Host = "10.20.xx.2xx"
smtp.Send(mailmsg)

2008年3月20日 星期四

用Vbscript 改檔名

Set objFSO = CreateObject("Scripting.FileSystemObject")
SourceFile=Server.MapPath("c:/test.asp") '要改的原始檔
TargetFile=Server.MapPath("c:/test1.asp") '新的檔名
objFSO.MoveFile SourceFile, TargetFile

在DTS中使用Activex 工作處理檔案--Copy

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()
dim fs,strfullpath,f
set fs=createobject("Scripting.FileSystemObject")



Const ForReading = 1, ForWriting = 2, ForAppending = 8
Dim f2
dim yyymm

Set f2 = fs.OpenTextFile("D:\SKBANK\BISsys\DATA\lnctbfy.dat", ForReading, True)

yyymm = f2.Read(5)



'Main=DTSTaskExecResult_Failure


fs.CopyFile "D:\SKBANK\BISsys\DATA\lnctbfy.dat", "D:\SKBANK\BISsys\DATA\"+yyymm+"lnctbfy.dat"

set fs=nothing
Main=DTSTaskExecResult_Success
End Function

在DTS中使用Activex 工作處理檔案

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()
dim fs,strfullpath,f
set fs=createobject("Scripting.FileSystemObject")
if (fs Is Nothing) then

Main=DTSTaskExecResult_Failure
'msgbox "1"
exit function

end if
strfullpath="D:\SFBAFK\BISsys\DATA\lnctbtt.dat"
if not fs.fileexists(strfullpath) then

Main=DTSTaskExecResult_Failure
'msgbox "2"
set fs=nothing
exit function
end if

Set f = fs.GetFile(strfullpath)


if f.size =0 then

Main=DTSTaskExecResult_Failure
'msgbox ""
set fs=nothing
exit function
end if
set fs=nothing
'msgbox "4"
'Main=DTSTaskExecResult_Failure
Main=DTSTaskExecResult_Success
End Function

在DTS中使用Active 工作執行DTS

'**********************************************************************
' Visual Basic ActiveX Script
'************************************************************************

Function Main()

dtsname="ImportBISTwd"
usrname="sa"
servername="MA03XXBXX"
pwd="sapwd"
DTSSQLStgFlag_Default2=0


dim objDTSPackage
dim objDTSStep
dim strResult
dim blnSucceeded

const DTSSQLStgFlag_Default = 0
const DTSStepExecResult_Failure = 1

set objDTSPackage = CreateObject("DTS.Package")

objDTSPackage.LoadFromSQLServer servername, usrname, pwd, DTSSQLStgFlag_Default2, "", "", "", dtsname
objDTSPackage.Execute

Main = DTSTaskExecResult_Success
End Function

2008年3月17日 星期一

DROP TABLE

IF EXISTS(SELECT name FROM sysobjects WHERE name = N'CUST'
AND type = 'U')
DROP TABLE CUST

Create Table Index

SET NOCOUNT OFF
USE MegaCenter
IF EXISTS (SELECT name FROM sysindexes
WHERE name = 'custid_idx')
DROP INDEX CUST.custid_idx
GO
USE MegaCenter
CREATE INDEX cust1id_idx
ON CUST (CID)
GO

2008年3月14日 星期五

BULK INSERT

BULK INSERT Cloris.dbo.Not3 FROM 'C:\Not3_2007.txt' WITH
( FIELDTERMINATOR =',' , ROWTERMINATOR =',\n' )
C:\Not3_2007.txt------------------------00118,黃河泉,1,
Cloris.dbo.Not3資料欄位
C1 varchar(5) C2 varchar(20) C3 varchar(1)

SQL Query-Dos命令

start isqlw -S ma0xxxxx02 -d Northwind -U sa -P sapwd

ADDLINKEDSERVER

USE master
--連到外部資料庫
EXEC sp_addlinkedserver @server='HR', @srvproduct='',
@provider='SQLOLEDB', @datasrc='MKxxxS0001'
--建立Login資料
EXEC sp_addlinkedsrvlogin 'HR', 'false', NULL, 'M6692', 'ssspwd'
--查詢已連結資料庫
EXEC sp_linkedservers
--刪除已連結資料庫
EXEC sp_dropserver ''HR'', 'droplogins'

2008年3月13日 星期四

用VB開啟檔案(IE,記事本)

Set ob = CreateObject("WScript.Shell")
ob.Run "Notepad D:\SKBANK\SendMail\HRPL.htm"
ob.Run "IEXPLORE " + App.Path + "\HRPL.htm"

2008年3月10日 星期一

用VB控制Excel

Dim ExcelApp As Excel.Application

Set ExcelApp = CreateObject("Excel.Application")
With ExcelApp
.Application.DisplayAlerts = False '抑制刪除警告提示訊息
.Workbooks.Open FileName:=App.Path + "\Sample.xls"
.Visible = True

.Workbooks.Open FileName:=strFileName + ".xls"

.Range("D" + CStr(i)).Select
strTmp = .ActiveCell.FormulaR1C1

.Range("A3:S" + CStr(i)).Select
.Selection.Copy
.Windows("Sample.xls").Activate
.Range("A" + CStr(m)).Select
.ActiveSheet.Paste
.Windows(FileName + ".xls").Close

.ActiveSheet.PageSetup.PrintArea = "$D$1:$K$" + CStr(m - 1)

.Columns("T:T").Select
.Selection.WrapText = True

'另存新檔
.ActiveWorkbook.SaveAs FileName:=App.Path + "\Merge.xls",FileFormat:=xlNormal, Password:="", WriteResPassword:="", ReadOnlyRecommended:=False, CreateBackup:=False
'關閉檔案
.ActiveWindow.Close

Set ExcelApp = Nothing

用VB控制ADODB.Connection

Set cnKPI = New ADODB.Connection

cnSQL = "Provider=SQLOLEDB.1;Persist Security Info=False;" & _
"USER ID = sa;password=xxxxx;initial catalog=KPxxxS;" & _
"Data Source=maxx05kxxxb"

cnKPI.ConnectionString = cnSQL

cnKPI.Open

用VB控制OutLookExchange發信

Dim olApp As Object
Dim Itm As Object


Dim FileName As String
Dim strBody As String

Set olApp = CreateObject("Outlook.Application")
Set Itm = olApp.CreateItem(0)
With Itm
.Subject = "薪資清冊及其它"
.To = strMail
.Body = "薪資清冊及其它"

.Attachments.Add strFileName1
.Attachments.Add strFileName2
'直接發信
' .Send
'儲存
' .Save
'啟動視窗

.Display

用VB控制FileSystem--開啟,建立文字檔

Dim fs, FileName, txtf
Set fs = CreateObject("Scripting.FileSystemObject")
FileName = "D:\Bank\" + strFileName

If fs.FileExists(FileName) Then
'資料加在文字檔後面
Set txtf = fs.OpenTextFile(FileName, 8, False)
Else
Set txtf = fs.CreateTextFile(FileName, True)
End If
txtf.WriteLine CStr(strString)
Set fs = Nothing
'刪除檔案
fs.DeleteFile (strFileName)