Saturday, January 18, 2020

base 64 convert to image

public Image LoadImage()
{
    //data:image/gif;base64,
    //this image is a single pixel (black)
    byte[] bytes = Convert.FromBase64String("R0lGODlhAQABAIAAAAAAAAAAACH5BAAAAAAALAAAAAABAAEAAAICTAEAOw==");

    Image image;
    using (MemoryStream ms = new MemoryStream(bytes))
    {
        image = Image.FromStream(ms);
    }

    return image;
}

Saturday, December 14, 2019

thousands separator for a column

SELECT REPLACE(CONVERT(VARCHAR, CONVERT(MONEY, TotalArea), 1), '.00', '') 
FROM table

Wednesday, December 4, 2019

MSQL password reset cmd



C:\WINDOWS\system32>Osql -S [computer_name] -E
1> EXEC sp_password NULL, ’123456’, ’sa’

Monday, December 2, 2019

FileUpload Control in Update Panel using ASP.NET AJAX

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<%
@ Register Assembly="AjaxControlToolkit" Namespace="AjaxControlToolkit" TagPrefix="ajaxToolkit" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<
html xmlns="http://www.w3.org/1999/xhtml">
<
head runat="server"><title>Untitled Page</title>
</
head>
<
body><form id="form1" runat="server"><asp:ScriptManager ID="ScriptManager1" runat="server" /><div><table width="50%" cellpadding="2" cellspacing="0"><tr><td><asp:UpdatePanel ID="UpdatePanel1" runat="server" UpdateMode="conditional"><ContentTemplate><asp:FileUpload ID="FileUpload1" runat="server" /><asp:Button ID="Upload" runat="server" Text="Upload" OnClick="Upload_Click" /><br /><asp:Image ID="NormalImage" runat="server" /></ContentTemplate><Triggers><asp:PostBackTrigger ControlID="Upload" /></Triggers></asp:UpdatePanel></td></tr></table></div></form>
</
body>
</
html>

Friday, November 29, 2019

Getting DataKeyNames for row on button click

protected void viewHoursButton_OnClick(object sender, EventArgs e)
{
    Button btn = sender as Button;
    GridViewRow row = btn.NamingContainer as GridViewRow;
    string pk = storyGridView.DataKeys[row.RowIndex].Values[0].ToString();
    System.Diagnostics.Debug.WriteLine(pk);
}

GridView button click event (sender)



 TextBox txt = (TextBox)sender;

 GridViewRow gvRow = (GridViewRow)txt.Parent.Parent;

 DropDownList ddl=(DropDownList)gvRow.FindControl("ddl");

Select the first day of a month in SQL

Month First Day


SELECT DATEADD(month, DATEDIFF(month, 0, @mydate), 0) AS StartOfMonth


SELECT
   DATEADD(yy, DATEDIFF(yy, 0, GETDATE()), 0) AS StartOfYear,
   DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, -1) AS LastDayOfYear,
   DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0) AS FirstOfNextYear,
   DATEADD(ms, -3, DATEADD(yy, DATEDIFF(yy, 0, GETDATE()) + 1, 0)) AS LastTimeOfYear

base 64 convert to image

public Image LoadImage() {     //data:image/gif;base64,     //this image is a single pixel (black)     byte[] bytes = Convert.FromBase6...