Public Sub RunOracleTransaction(ByVal connectionString As String) Using connection As New OracleConnection(connectionString) connection.Open() Dim command As OracleCommand = connection.CreateCommand() Dim transaction As OracleTransaction ' Start a local transaction transaction = connection.BeginTransaction(IsolationLevel.ReadCommitted) ' Assign transaction object for a pending local transaction command.Transaction = transaction Try command.CommandText = _ "INSERT INTO Dept (DeptNo, Dname, Loc) values (50, 'TECHNOLOGY', 'DENVER')" command.ExecuteNonQuery() command.CommandText = _ "INSERT INTO Dept (DeptNo, Dname, Loc) values (60, 'ENGINEERING', 'KANSAS CITY')" command.ExecuteNonQuery() transaction.Commit() Console.WriteLine("Both records are written to database.") Catch e As Exception transaction.Rollback() Console.WriteLine(e.ToString()) Console.WriteLine("Neither record was written to database.") End Try End Using End Sub
2017年6月3日 星期六
OracleConnection.BeginTransaction 方法 ()
2016年2月24日 星期三
取得系統路徑
取得系統路徑 參考
Dim filder As string
Dim filder As string
= Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
ApplicationData 表示做為目前漫遊使用者的應用程式特定資料之通用儲存機制的目錄。
漫遊使用者在網路上以一個以上的電腦工作。
漫遊使用者的設定檔保留在網路伺服器上,且當使用者登入時載入系統。
CommonApplicationData 表示做為所有使用者使用的應用程式特定資料之通用儲存機制的目錄。
CommonProgramFiles 表示在應用程式間共享的元件的目錄。
Cookies 表示做為網際網路 Cookie 通用儲存機制的目錄。
Desktop 邏輯的 [桌面],而不是實體的檔案系統位置。
DesktopDirectory 表示用來實際儲存桌面上檔案物件的目錄。
這個目錄不可與虛擬的桌面資料夾混淆。
Favorites 表示做為使用者的我的最愛項目之通用儲存機制的目錄。
History 表示做為網際網路記錄項目通用儲存機制的目錄。
InternetCache 表示做為網際網路暫存檔通用儲存機制的目錄。
LocalApplicationData 表示做為目前非漫遊使用者使用的應用程式特定資料之通用儲存機制的目錄。
MyComputer [我的電腦] 資料夾。 注意事項:
MyComputer 常數永遠都會產生空字串 (""),因為並沒有為 [我的電腦] 資料夾定義路徑。
MyDocuments [我的文件] 資料夾。
MyMusic [我的音樂] 資料夾。
MyPictures [我的圖片] 資料夾。
Personal 表示做為文件通用儲存機制的目錄。
ProgramFiles Program Files 目錄。
Programs 包含使用者程式群組的目錄。
Recent 包含使用者最近使用之文件的目錄。
SendTo 包含 [傳送到] 功能表項目的目錄。
StartMenu 包含 [開始] 功能表項目的目錄。
Startup 對應至使用者 [啟動] 程式群組的目錄。
每當使用者登入或啟動 Windows NT 或更新的版本,
或啟動 Windows 98 時,系統會啟動這些程式。
System System 目錄。
Templates 表示做為文件樣板 (Template) 通用儲存機制的目錄。
將『Environment.SpecialFolder.DesktopDirectory』中的DesktopDirectory替換成想要的資料夾即可。
另外,最常用到的程式所在的資料夾:
Application.StartupPath
2016年2月17日 星期三
強制下載檔案
強制下載檔案 參考
IE下載中文檔名出現亂碼 參考
在下載的名稱加上HttpUtility.UrlPathEncode
ex.
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(FileName)))
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim index As Integer = CType(CType(sender, LinkButton).Parent.Parent, GridViewRow).RowIndex
Dim lb_url As Label = CType(GridView1.Rows(index).FindControl("lb_url"), Label)
Dim p_url As String = Server.MapPath(lb_url.Text)
Dim wc As New System.Net.WebClient()
Dim a As Byte() = wc.DownloadData(p_url)
Dim FileName As String = System.IO.Path.GetFileName(p_url)
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", FileName))
Response.BinaryWrite(a)
Response.End()
End Sub
Dim index As Integer = CType(CType(sender, LinkButton).Parent.Parent, GridViewRow).RowIndex
Dim lb_url As Label = CType(GridView1.Rows(index).FindControl("lb_url"), Label)
Dim p_url As String = Server.MapPath(lb_url.Text)
Dim wc As New System.Net.WebClient()
Dim a As Byte() = wc.DownloadData(p_url)
Dim FileName As String = System.IO.Path.GetFileName(p_url)
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", FileName))
Response.BinaryWrite(a)
Response.End()
End Sub
IE下載中文檔名出現亂碼 參考
在下載的名稱加上HttpUtility.UrlPathEncode
ex.
Response.AddHeader("Content-Disposition", String.Format("attachment; filename={0}", HttpUtility.UrlPathEncode(FileName)))
2016年1月7日 星期四
VB字串處理
字串 逐字取出
If Session("Ins_Part").ToString <> "null" Then
Dim j As Integer = Nothing
For i As Integer = 0 To Session("Ins_Part").ToString.Length - 1
If Session("Ins_Part").ToString(i) = "," Then
j += 1
End If
Next
End If
字串分割為陣列
Dim urlNameSlipt As String() = Session("urlName").Split(",") '分割字串
For i As Integer = 0 To urlNameSlipt.Length - 1
xxx.Text += urlNameSlipt(i) & "/"
Next
遞減迴圈
For i = 4 To 0 Step -1
Next
左側不足補0
If Session("Ins_Part").ToString <> "null" Then
Dim j As Integer = Nothing
For i As Integer = 0 To Session("Ins_Part").ToString.Length - 1
If Session("Ins_Part").ToString(i) = "," Then
j += 1
End If
Next
End If
字串分割為陣列
Dim urlNameSlipt As String() = Session("urlName").Split(",") '分割字串
For i As Integer = 0 To urlNameSlipt.Length - 1
xxx.Text += urlNameSlipt(i) & "/"
Next
遞減迴圈
For i = 4 To 0 Step -1
Next
左側不足補0
Dim seq2 As String = seq1.PadLeft(5, "0")
字串轉換數字
Cint
取到小數第n位
TextBox1.Text = Format(data, ".##") '最後一位為0則不顯示 '四捨五入
TextBox1.Text = Format(data, ".00") '最後一位為0亦顯示
指定Label日期顯示格式
<asp:Label ID="lb1" runat="server" Text='<%# Bind("CONFIRM_DATE", "{0:yyyy/MM/dd}") %>'></asp:Label>
字串轉換數字
Cint
取到小數第n位
TextBox1.Text = Format(data, ".##") '最後一位為0則不顯示 '四捨五入
TextBox1.Text = Format(data, ".00") '最後一位為0亦顯示
指定Label日期顯示格式
<asp:Label ID="lb1" runat="server" Text='<%# Bind("CONFIRM_DATE", "{0:yyyy/MM/dd}") %>'></asp:Label>
訂閱:
文章 (Atom)