Monday, July 30, 2007
[C#.Net] Get Response Data from 3rd Party Web Service
WebResponse response;
string url = "https://www.nbdgateway.net/xmlgateway/affiliatelogin.do";
string postdata = "affiliatecode=backcheck&username=sa&password=pass&ssn=1&product=AIM";
request = WebRequest.Create(url);
request.Method = "POST";
//request.Referer = url;
request.ContentLength = postdata.Length;
request.ContentType = "application/x-www-form-urlencoded";
StreamWriter sw;
StreamReader sr;
// post data
sw = new StreamWriter(request.GetRequestStream());
sw.Write(postdata);
sw.Close();
//get result
response = request.GetResponse();
sr = new StreamReader(response.GetResponseStream());
string result = sr.ReadToEnd();
sr.Close();
textBox1.Text = result;
Sunday, July 29, 2007
[SQL] Date Functions
DATEPART ( datepart , date )
Day of the Week
SELECT DATEPART(dw,GETDATE())
Year
SELECT DATEPART(yy,GETDATE())
SELECT DATEPART(yyyy,GETDATE())
Quarter
SELECT DATEPART(q,GETDATE())
SELECT DATEPART(qq,GETDATE())
Month
SELECT DATEPART(m,GETDATE())
SELECT DATEPART(mm,GETDATE())
Day of the Year
SELECT DATEPART(y,GETDATE())
SELECT DATEPART(dy,GETDATE())
Month Day
SELECT DATEPART(d,GETDATE())
SELECT DATEPART(dd,GETDATE())
Week
SELECT DATEPART(wk,GETDATE())
SELECT DATEPART(ww,GETDATE())
Hour
SELECT DATEPART(hh,GETDATE())
Minute
SELECT DATEPART(n,GETDATE())
SELECT DATEPART(mi,GETDATE())
Second
SELECT DATEPART(s,GETDATE())
SELECT DATEPART(ss,GETDATE())
Millisecond
SELECT DATEPART(ms,GETDATE())
Wednesday, July 25, 2007
[SQL] Convert VARCHAR To VARBINARY
DECLARE @Password varchar(50)
SET @Password = 'MLAV'
SELECT CONVERT(varbinary(50), @Password)
Wednesday, July 18, 2007
[ASP.Net] Get Object Value from User Control
UserControl.FindControl method
TextBox firstNameTextBox = (TextBox) uc1.FindControl("firstNameTextBox");
Wednesday, July 11, 2007
[SQL] Get Number of Days in a Month Function
REATE FUNCTION [dbo].[GetDaysInMonth] ( @pDate DATETIME )
RETURNS INT
AS
BEGIN
RETURN CASE WHEN MONTH(@pDate) IN (1, 3, 5, 7, 8, 10, 12) THEN 31
WHEN MONTH(@pDate) IN (4, 6, 9, 11) THEN 30
ELSE CASE WHEN (YEAR(@pDate) % 4 = 0 AND
YEAR(@pDate) % 100 != 0) OR
(YEAR(@pDate) % 400 = 0)
THEN 29
ELSE 28
END
END
END
GO
[C#.Net] Code: Determining the Span Between Two Dates
DateTime oldDate = new DateTime(2002,7,15);
DateTime newDate = DateTime.Now;
// Difference in days, hours, and minutes.
TimeSpan ts = newDate - oldDate;
// Difference in days.
int differenceInDays = ts.Days;
Console.WriteLine("Difference in days: {0} ", differenceInDays);
Download Compiled Code : http://ayette.net/ComputeHoursWork.rar
Download Sample Code: http://ayette.net/ComputeHoursWork.rar
[VB.Net] Get Last Day of the Month
Function LastOfThisMonth() As Date
LastOfThisMonth = DateAdd("d", -1, FirstOfNextMonth)
End Function
Function FirstOfNextMonth() As Date
Dim dtm As Date
dtm = Date
FirstOfNextMonth = DateSerial(Year(dtm),
Month(dtm) + 1, 1)
End Function
[JavaScript] Prevent Previous Button/ALT-LEFT
<script language="javascript">
history.forward(history.length - 1)
/script>
[General] MSDE: login failed for user '(null)'. Reason: Not associated with a trusted SQL server
How To Verify and Change the MSDE System Administrator Password
http://support.microsoft.com/default.aspx?scid=kb;en-us;322336
[SQL] Get UniqueIdentifier (Stored Procedure)
CREATE PROCEDURE
(
@OrderID uniqueidentifier out
)
AS
SET @OrderID = NewID()
GO
[ASP.Net] Export To EXCEL file without using Office Object
Response.Clear()
Response.Buffer = True
Response.ContentType = "application/vnd.ms-excel"
Response.AddHeader("Content-Disposition", "attachment;filename= sample.xls")
Dim sbldTable As New StringBuilder
sbldTable.Append("
").Append("Sample Data") sbldTable.Append(" | ")
Response.Write(sbldTable.ToString)
sbldTable = Nothing
Response.End()
[C#.Net] Random Numbers
Random rndNumber =
[ASP.Net] Prevent caching of page by the browser
Response.Cache.SetAllowResponseInBrowserHistory(false);