顯示具有 ASP.NET VB 標籤的文章。 顯示所有文章
顯示具有 ASP.NET VB 標籤的文章。 顯示所有文章

2014年5月21日 星期三

換列語法vb c#

VB
Constants.vbCrLf

C#
System.Environment.NewLine

VB的IsDBNull C#的 Convert.IsDBNull() 函數用法

Convert.IsDBNull()返回有關指定物件是否為 DBNull 類型的指示,即是用來判斷物件是否為DBNULL的。其返回值是True或Flase。

VB

IsDBNull(objDataReader_name["my_all"]) == true

C#

Convert.IsDBNull(objDataReader_name["my_all"]) == true

2014年3月30日 星期日

GridView72絕技-文字變顏色


前台展示結果:


後台程式碼:
Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles GridView1.RowDataBound
        Dim oRow As Data.DataRowView
        Dim oFontColor As System.Drawing.Color = Drawing.Color.Empty

        If e.Row.RowType = DataControlRowType.DataRow Then
            oRow = CType(e.Row.DataItem, Data.DataRowView)
            '文字變顏色條件
             If oRow("欄位名稱") < 1 Then
                oFontColor = Drawing.Color.Black
            Else
                oFontColor = Drawing.Color.Red
            End If

            e.Row.ForeColor = oFontColor
        End If
    End Sub

2014年3月7日 星期五

gridview72絕技之一-螢光棒效果DataControlRowType

前台-必須加上OnRowDataBound="GridView1_RowDataBound

   <asp:GridView ID="GridView1" runat="server" AllowPaging="True" 
            AllowSorting="True" AutoGenerateColumns="False" DataSourceID="SqlDataSource2" 
            Font-Bold="True" Font-Size="Medium" PageSize="12" Width="1200px" 
            DataKeyNames="uid" OnRowDataBound="GridView1_RowDataBound">


=======================================================================
後台

  Protected Sub GridView1_RowDataBound(ByVal sender As Object, ByVal e As GridViewRowEventArgs)
        Dim i As Integer

        For i = 0 To GridView1.Rows.Count - 1

            If e.Row.RowType = DataControlRowType.DataRow Then

                e.Row.Attributes.Add("onmouseover", "c=this.style.backgroundColor;this.style.backgroundColor='#CEFF63'")

                e.Row.Attributes.Add("onmouseout", "this.style.backgroundColor=c")
            End If
        Next
    End Sub





2014年3月2日 星期日

資料庫及檔案CONNECTION語法


1.Access數據庫的DSN-less連接方法:
set adocon=Server.Createobject("adodb.connection")
adoconn.Open"Driver={Microsoft Access Driver(*.mdb)};DBQ="& _
Server.MapPath("數據庫所在路徑")
2.Access OLE DB連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Provider=Microsoft.Jet.OLEDB.4.0;"& _
"Data Source=" & Server.MapPath("數據庫所在路徑")
3.SQL server連接方法:
set adocon=server.createobject("adodb.recordset")
adocon.Open"Driver={SQL Server};Server=(Local);UID=***;PWD=***;"& _
"database=數據庫名;"
4.SQL server OLE DB連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"provider=SQLOLEDB.1;Data Source=RITANT4;"& _
"user ID=***;Password=***;"& _
"inital Catalog=數據庫名"
5.Oracle 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft odbc for oracle};server=oraclesever.world;uid=admin;pwd=pass;"
6.Oracle OLE DB 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Provider=OraOLEDB.Oracle;data source=dbname;user id=admin;password=pass;"
7.dBase 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft dbase driver(*.dbf)};driverid=277;dbq=------------;"
8.mySQL 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={mysql};database=yourdatabase;uid=username;pwd=yourpassword;option=16386;"
9.Visual Foxpro 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft Visual Foxpro driver};sourcetype=DBC;sourceDB=*.dbc;Exclusive=No;"
10.MS text 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Driver={microsoft text driver(*.txt; *.csv)};dbq=-----;"&_
"extensions=asc,csv,tab,txt;Persist SecurityInfo=false;"
11.MS text OLE DB 連接方法:
set adocon=Server.Createobject("adodb.connection")
adocon.open"Provider=microsof.jet.oledb.4.0;data source=your_path;"&_
"Extended Properties'text;FMT=Delimited'"

2014年2月20日 星期四

Page_Unload關閉資料釋放記憶體


Protected Sub Page_Unload(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Unload

        objcmd.Dispose()
        objcmd = Nothing

   

        objcon.Close()
        objcon.Dispose()
        objcon = Nothing
        GC.Collect(0, System.GCCollectionMode.Forced)

    End Sub

2014年1月11日 星期六

Asp.net匯出chart

Protected Sub btnExportExcel_Click(sender As Object, e As EventArgs)
    Response.Clear()
    Response.Buffer = True
    Response.AddHeader("content-disposition", "attachment;filename=ChartExport.xls")
    Response.ContentType = "application/vnd.ms-excel"
    Response.Charset = ""
    Dim sw As New StringWriter()
    Dim hw As New HtmlTextWriter(sw)
    Chart1.RenderControl(hw)
    Dim src As String = Regex.Match(sw.ToString(), "<img.+?src=[""'](.+?)[""'].+?>", RegexOptions.IgnoreCase).Groups(1).Value
    Dim table As String = "<table><tr><td><img src='{0}' /></td></tr></table>"
    table = String.Format(table, Request.Url.GetLeftPart(UriPartial.Authority) + src)
    Response.Write(table)
    Response.Flush()
    Response.End()
End Sub

2013年10月25日 星期五

textbox中換行字元怎麼寫...

TextBox1.Text="Hello!!你好" & vbCrLf & "請在這裡輸入你想留言的文字" & vbCrLf & "start"

2013年10月5日 星期六

ASP.NET-JavaScript alert用法


由於本身也在寫一些ASP.NET,以後也把一些遇到的問題和解決方式寫出來,順便幫自己做筆記。
在程式設計時可以用Msgbox來顯示警告視窗,但移到正式環境就會出錯。
所以在Client顯示警告視窗可以用
Response.Write(" ")
或在頁面上加入一個Literal控制項再加入
Me.Literal1.Text = " "
另外導入頁面可以用
Response.Write(" ")

Response.Redirect("index.aspx")
但是將兩個功能放在一起,就會直接導到頁面,不會出現警告訊息。
這時可以在最後加入Response.End()即可解決(但不能使用Response.Redirect)另外用window.open會被瀏覽器擋住,所以可以使用location.href或window.location來取代,又由於location.href有些瀏覽器已經不支援,故建議使用window.location
範例如下
Response.Write(" ")
Response.End()
以上皆為後置程式碼(.vb或.cs)內之程式。

滑鼠移動改變按鈕圖片,onmouseover,onmouseout


 '使用HTML語法+java script可以得到效果
'圖片檔案格式建議jpg或gif
<a href="/user_power.aspx"  target="_parent">

<img alt=""提示訊息"" src="../test/test.jpg"
onmouseover="this.src='/test/test_over.gif'" onmouseout="this.src='/test/test.jpg'"border="0" title="ASP.NET提示訊息" />

</a>

textbox配合PopupControlExtender-選擇日期


'前台
        PopupControlID="pnlCalendar" TargetControlID="tbReturn" Position="Bottom" >

'後台
Protected Sub c1_SelectionChanged(sender As Object, e As System.EventArgs) Handles c1.SelectionChanged

        Me.PopupControlExtender1.Commit(Me.c1.SelectedDate.Date)
    End Sub

AnimationExtender 淡入淡出onload

 <asp:AnimationExtender ID="Menu1_AnimationExtender" runat="server" TargetControlID="Panel1">   
          <Animations>  
             <OnLoad>  
                <Sequence>   
                  <FadeIn AnimationTarget="Panel1" Duration="5" Fps="20" maximumOpacity="0.8" minimumOpacity="0.1">
                  </FadeIn>
                 </Sequence>  
               </OnLoad>  
              </Animations>     
           </asp:AnimationExtender>

2013年10月4日 星期五

計算兩日期時間差異天數TimeSpan Subtract


         Dim sd As Date = TextBox_sd1.Text
        Dim ed As Date = TextBox_ed1.Text
        '計算兩日期時間差
        Dim vd As TimeSpan = ed.Subtract(sd)
       '差異天數
        Dim my_vd As Integer = vd.TotalDays
   

2013年10月2日 星期三

日期時間差範例


Protected Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim bft As Date = TextBox1.Text
        Dim att As Date = TextBox2.Text
        Dim min As TimeSpan = att.Subtract(bft)
        Dim my_min As Integer = min.TotalMinutes
        Response.Write("時間差(分):" & my_min)
    End Sub


2013年9月25日 星期三

SQLserver 時間預設值


1.日期時間
(getdate())

2.今天日期
(CONVERT([smalldatetime],(((CONVERT([char](4),datepart(year,getdate()),(0))+'-')+CONVERT([char](2),datepart(month,getdate()),(0)))+'-')+CONVERT([char](2),datepart(day,getdate()),(0)),(0)))



3.SQL語法
DateTime a = DateTime.Now;
string sql="Insert into test(這裡要指定欄位名稱) values('" + a.ToSTring("yyyy/MM/dd HH:mm:ss") + "')";
或者,直接寫成
string sql="Insert into test(這裡要指定欄位名稱) values(getdate())";
即可
ps.如果直接下DateTime.now會產生字串問題

介紹DLL不錯的文章


為什麼要使用 DLL (Dynamic Linking Library) - 動態連結檔 ?

        微軟當初為Windows設計動態連結檔主要是擷取它的兩項優點:一是動態連結、一是資源共享。資源共享的例子相當顯而易見,例如之前曾經提過Windows有三個核心的動態連結檔:Kernel主要是負責系統和應用程式的記憶體、行程和執行緒等等的管理工作User主要負責使用者介面和訊息的傳遞;GDI則負責系統的任何圖形繪製、顯示等工作。而這些動態連結檔所提供的任何函數都可以在必要的時候,讓每一個Windows環境底下的執行檔使用。因為DLL具備節省記憶體的特性,因此自從Windows 3.1版以來,它就逐漸成為Windows程式設計的主流

將HTML標籤轉成文字-HtmlEncode


'在前台<%@ Page %>'插入ValidateRequest="false"
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default"  ValidateRequest="false"%>
' Visual BasicPrivate Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim userinput As String = TextBox1.Text
userinput = Server.HtmlEncode(userinput)' Accepts , case-insensitive
userinput = userinput.Replace("<b>", "")
userinput = userinput.Replace("</b>", "
")
userinput = userinput.Replace("<B>", "")
userinput = userinput.Replace("</B>", "
")
userinput = userinput.Replace("<u>", "")
userinput = userinput.Replace("</u>", "
")
userinput = userinput.Replace("<U>", "")
userinput = userinput.Replace("</U>", "
")
Label1.Text = userinput
End Sub

ASP.NET 珊除檔案


'執行button或form load實執行下列語法
File.Delete(Server.MapPath("/path/filename"))

具有潛在危險Request.Form 的值已從用戶端偵測到(解決方法)


具有潛在危險Request.Form 的值已從用戶端偵測到(解決方法)

在Asp.Net的網站操作中,會產生『具有潛在危險 Request.Form 的值已從用戶端偵測到』此錯誤訊息之原因,通常是在PostBack後系統偵測到頁面中存在某些文字輸入欄位如TextBox、Html編輯器(如FckEditor)等文字內容中存在Html語法,因而判斷為惡意程式碼,如此來避免駭客的惡意攻擊。

此防禦功能在Asp.Net中預設是開啟的,可以透過在頁面的Page指示詞中加入 validateRequest="False" 來關閉它。即可避免資料送出後系統將Html語法判斷為惡意程式碼。

Ex:
<%@ Page Language="VB" AutoEventWireup="false" CodeFile="Test.aspx.vb" Inherits="Test" validateRequest="False" %>

另一種關閉方式是透過 web.config 設定檔來達到整個網站皆關閉防禦功能的效果。但是非常不建議直接在web.config 設定檔中作關閉的動作,這樣對系統的登入驗證頁面來說等於開了窗,非常危險。