2013 m. spalio 7 d., pirmadienis

Tipų konvertavimas: ToBase64String

Modern applications increasingly use plain text to store and share data, especially in XML and SOAP formats. However, binary data cannot be represented directly in plain text, so one popular method is to convert binary to Base64 format.

What is Base64?

Base64 converts binary data to plain text using 64 case-sensitive, printable ASCII characters: A-Z, a-z, 0-9, plus sign (+) and forward slash (/), and may be terminated with 0-2 “padding” characters represented by the equal sign (=). For example, the eight-byte binary data in hex “35 71 4d 8e 4c 5f db 42″ converts to Base64 text as “NXFNjkxf20I=”.

.NET Convert Methods

Generally, to convert between Base64 and plain text, you should use the .NET methods Convert.ToBase64String and Convert.FromBase64String.

Custom Conversions


However, there may be instances when you want to modify the Base64 standard conversion behavior. For example, applications may use Base64 in file paths or URLs to represent globally unique IDs and other binary data. However, the forward slash is an invalid character in file paths. In URLs, the ‘+’ and ‘/’ characters translate into special percent-encoded hexadecimal sequences (‘+’ = ‘%2B’ and ‘/’ = ‘%2F’), and databases may choke on the % character because it represents a wildcard in ANSI SQL. Therefore, a modified “Base64 for URL” variant exists, where no ‘=’ padding is used, and the ‘+’ and ‘/’ characters are replaced with the hyphen ‘-’ and underscore ‘_’, respectively.


Function getBase64Text(ByVal sInput As String) As String
        Return System.Convert.ToBase64String(System.Text.Encoding.UTF8.GetBytes(sInput))
    End Function

http://www.csharp411.com/convert-binary-to-base64-string/

2013 m. spalio 3 d., ketvirtadienis

Mod and division in Visual Basic

Dim hrs As Integer = allmins \ 60
Dim minutes As Integer = allmins Mod 60

Related operators include the following:

2013 m. rugsėjo 25 d., trečiadienis

AsyncPostBackTrigger nenaudoti su Response.Write

Dideliuose projektuose, kur daug JavaScript bibliotekų ir UpdatePanel, gaunama "mistinė" klaida dėl to, kad vb kode buvo panaudotas Response.Write

2013 m. rugsėjo 19 d., ketvirtadienis

Unikalių ID generavimas GridView eilutėms

 < asp : GridView ID =" grdTest " runat = " server " AutoGenerateColumns = " False " ClientIDMode = " AutoID "
            DataKeyNames = " ID ">
< / asp : GridView >


Jeigu GridView nurodome ClientIDMode, tai dar nereiškia, kad kiekvienai eilutei bus sugeneruotas unikalus ID. Jis generuojamas tik tada, jei RowDataBound įvykyje kviečiame e.Row.ClientID.

 Protected Sub grdTest_RowDataBound(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.GridViewRowEventArgs) Handles grdTest.RowDataBound

        If e.Row.RowType = DataControlRowType.Header Then
            hlDuplicate.NavigateUrl = "javascript:duplRow(" & oRW("ID") & ",'" & e.Row.ClientID & "')"
        End If

End If

2013 m. rugsėjo 17 d., antradienis

Kaip konvertuoti vieną stulpelio tipą į kitą tipą


ALTER TABLE table_name ADD new_column_name decimal(18,2)

update table_name
set new_column_name = convert(decimal(18,2), old_column_name)

ALTER TABLE table_name DROP COLUMN old_column_name