Public Class Form1
Dim day_a As DateTime = Now
Dim day_b As DateTime
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
day_b = Now
Dim m_int As Integer = CInt(DateDiff(DateInterval.Second, day_a, day_b) / 60)
Dim s_int As Integer = DateDiff(DateInterval.Second, day_a, day_b) Mod 60
Dim ms_str As String = " 共" & m_int & "分" & s_int & "秒"
MessageBox.Show(ms_str)
End Sub
End Class
2010年10月19日 星期二
2010年10月8日 星期五
如何開啟 ADO 連線和資料錄集物件
微軟官網
---
這篇真是精華 保存起來!!
---
Option Explicit
Private Sub cmdOpen_Click()
Dim Conn1 As New adodb.Connection
Dim Cmd1 As New adodb.Command
Dim Errs1 As Errors
Dim Rs1 As New adodb.Recordset
Dim i As Integer
Dim AccessConnect As String
' Error Handling Variables
Dim errLoop As Error
Dim strTmp As String
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=nwind.mdb;" & _
"DefaultDir=C:\program files\devstudio\vb;" & _
"Uid=Admin;Pwd=;"
'---------------------------
' Connection Object Methods
'---------------------------
On Error GoTo AdoError ' Full Error Handling which traverses
' Connection object
' Connection Open method #1: Open via ConnectionString Property
Conn1.ConnectionString = AccessConnect
Conn1.Open
Conn1.Close
Conn1.ConnectionString = ""
' Connection Open method #2: Open("[ODBC Connect String]","","")
Conn1.Open AccessConnect
Conn1.Close
' Connection Open method #3: Open("DSN","Uid","Pwd")
Conn1.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=nwind.mdb;" & _
"DefaultDir=C:\program files\devstudio\vb;" & _
"Uid=Admin;Pwd=;"
Conn1.Close
'--------------------------
' Recordset Object Methods
'--------------------------
' Don't assume that we have a connection object.
On Error GoTo AdoErrorLite
' Recordset Open Method #1: Open via Connection.Execute(...)
Conn1.Open AccessConnect
Set Rs1 = Conn1.Execute("SELECT * FROM Employees")
Rs1.Close
Conn1.Close
' Recordset Open Method #2: Open via Command.Execute(...)
Conn1.ConnectionString = AccessConnect
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "SELECT * FROM Employees"
Set Rs1 = Cmd1.Execute
Rs1.Close
Conn1.Close
Conn1.ConnectionString = ""
' Recordset Open Method #3: Open via Command.Execute(...)
Conn1.ConnectionString = AccessConnect
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "SELECT * FROM Employees"
Rs1.Open Cmd1
Rs1.Close
Conn1.Close
Conn1.ConnectionString = ""
' Recordset Open Method #4: Open w/o Connection & w/Connect String
Rs1.Open "SELECT * FROM Employees", AccessConnect, adOpenForwardOnly
Rs1.Close
Done:
Set Rs1 = Nothing
Set Cmd1 = Nothing
Set Conn1 = Nothing
Exit Sub
AdoError:
i = 1
On Error Resume Next
' Enumerate Errors collection and display properties of
' each Error object (if Errors Collection is filled out)
Set Errs1 = Conn1.Errors
For Each errLoop In Errs1
With errLoop
strTmp = strTmp & vbCrLf & "ADO Error # " & i & ":"
strTmp = strTmp & vbCrLf & " ADO Error # " & .Number
strTmp = strTmp & vbCrLf & " Description " & .Description
strTmp = strTmp & vbCrLf & " Source " & .Source
i = i + 1
End With
Next
AdoErrorLite:
' Get VB Error Object's information
strTmp = strTmp & vbCrLf & "VB Error # " & Str(Err.Number)
strTmp = strTmp & vbCrLf & " Generated by " & Err.Source
strTmp = strTmp & vbCrLf & " Description " & Err.Description
MsgBox strTmp
' Clean up gracefully without risking infinite loop in error handler
On Error GoTo 0
GoTo Done
End Sub
---
這篇真是精華 保存起來!!
---
Option Explicit
Private Sub cmdOpen_Click()
Dim Conn1 As New adodb.Connection
Dim Cmd1 As New adodb.Command
Dim Errs1 As Errors
Dim Rs1 As New adodb.Recordset
Dim i As Integer
Dim AccessConnect As String
' Error Handling Variables
Dim errLoop As Error
Dim strTmp As String
AccessConnect = "Driver={Microsoft Access Driver (*.mdb)};" & _
"Dbq=nwind.mdb;" & _
"DefaultDir=C:\program files\devstudio\vb;" & _
"Uid=Admin;Pwd=;"
'---------------------------
' Connection Object Methods
'---------------------------
On Error GoTo AdoError ' Full Error Handling which traverses
' Connection object
' Connection Open method #1: Open via ConnectionString Property
Conn1.ConnectionString = AccessConnect
Conn1.Open
Conn1.Close
Conn1.ConnectionString = ""
' Connection Open method #2: Open("[ODBC Connect String]","","")
Conn1.Open AccessConnect
Conn1.Close
' Connection Open method #3: Open("DSN","Uid","Pwd")
Conn1.Open "Driver={Microsoft Access Driver (*.mdb)};" & _
"DBQ=nwind.mdb;" & _
"DefaultDir=C:\program files\devstudio\vb;" & _
"Uid=Admin;Pwd=;"
Conn1.Close
'--------------------------
' Recordset Object Methods
'--------------------------
' Don't assume that we have a connection object.
On Error GoTo AdoErrorLite
' Recordset Open Method #1: Open via Connection.Execute(...)
Conn1.Open AccessConnect
Set Rs1 = Conn1.Execute("SELECT * FROM Employees")
Rs1.Close
Conn1.Close
' Recordset Open Method #2: Open via Command.Execute(...)
Conn1.ConnectionString = AccessConnect
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "SELECT * FROM Employees"
Set Rs1 = Cmd1.Execute
Rs1.Close
Conn1.Close
Conn1.ConnectionString = ""
' Recordset Open Method #3: Open via Command.Execute(...)
Conn1.ConnectionString = AccessConnect
Conn1.Open
Cmd1.ActiveConnection = Conn1
Cmd1.CommandText = "SELECT * FROM Employees"
Rs1.Open Cmd1
Rs1.Close
Conn1.Close
Conn1.ConnectionString = ""
' Recordset Open Method #4: Open w/o Connection & w/Connect String
Rs1.Open "SELECT * FROM Employees", AccessConnect, adOpenForwardOnly
Rs1.Close
Done:
Set Rs1 = Nothing
Set Cmd1 = Nothing
Set Conn1 = Nothing
Exit Sub
AdoError:
i = 1
On Error Resume Next
' Enumerate Errors collection and display properties of
' each Error object (if Errors Collection is filled out)
Set Errs1 = Conn1.Errors
For Each errLoop In Errs1
With errLoop
strTmp = strTmp & vbCrLf & "ADO Error # " & i & ":"
strTmp = strTmp & vbCrLf & " ADO Error # " & .Number
strTmp = strTmp & vbCrLf & " Description " & .Description
strTmp = strTmp & vbCrLf & " Source " & .Source
i = i + 1
End With
Next
AdoErrorLite:
' Get VB Error Object's information
strTmp = strTmp & vbCrLf & "VB Error # " & Str(Err.Number)
strTmp = strTmp & vbCrLf & " Generated by " & Err.Source
strTmp = strTmp & vbCrLf & " Description " & Err.Description
MsgBox strTmp
' Clean up gracefully without risking infinite loop in error handler
On Error GoTo 0
GoTo Done
End Sub
2010年10月6日 星期三
如何取得一目錄中的檔案個數
using System.IO;
...
DirectoryInfo di = new DirectoryInfo("C:\\book");
FileInfo[] files = di.GetFiles();
int fileCount = files.Length;
...
DirectoryInfo di = new DirectoryInfo("C:\\book");
FileInfo[] files = di.GetFiles();
int fileCount = files.Length;
如何尋找檔案並取得該檔案的路徑
Dim s() As String = Directory.GetFiles("c:\winnt", "*.bmp", SearchOption.AllDirectories)
For i As Integer = 0 To s.Length - 1
Debug.WriteLine(s(i))
Next
For i As Integer = 0 To s.Length - 1
Debug.WriteLine(s(i))
Next
2007 Office system 驅動程式的資料連線元件
微軟官網
這個下載將會安裝一組元件,可供非 Microsoft Office 應用程式用來讀取 2007 Office system 檔案中的資料,例如 Microsoft Office Access 2007 (mdb 和 accdb) 檔案以及 Microsoft Office Excel 2007 (xls、xlsx 和 xlsb) 檔案。也支援連線至 Microsoft Windows SharePoint Services 和文字檔案。
應用程式開發人員可安裝 ODBC 和 OLEDB 驅動程式,在開發連線至 Office 檔案格式的應用程式時使用。
---
這意思看起,該是採用VB6開發不必再呼叫application 的樣子了!? 待有空再測了...
這個下載將會安裝一組元件,可供非 Microsoft Office 應用程式用來讀取 2007 Office system 檔案中的資料,例如 Microsoft Office Access 2007 (mdb 和 accdb) 檔案以及 Microsoft Office Excel 2007 (xls、xlsx 和 xlsb) 檔案。也支援連線至 Microsoft Windows SharePoint Services 和文字檔案。
應用程式開發人員可安裝 ODBC 和 OLEDB 驅動程式,在開發連線至 Office 檔案格式的應用程式時使用。
---
這意思看起,該是採用VB6開發不必再呼叫application 的樣子了!? 待有空再測了...
訂閱:
文章 (Atom)