Sunday, October 24, 2010
SQL number with .00 decimal 2 disgits
Query
SELECT CONVERT(VARCHAR,CONVERT(VARCHAR,786),0) as Currency_COL
Result
------------------
Currency_COL
------------------
780.00
------------------
Saturday, October 16, 2010
DateTime.ToString() Patterns
DateTime.ToString() Patterns
All the patterns:
0 | MM/dd/yyyy | 08/22/2006 |
1 | dddd, dd MMMM yyyy | Tuesday, 22 August 2006 |
2 | dddd, dd MMMM yyyy | HH:mm Tuesday, 22 August 2006 06:30 |
3 | dddd, dd MMMM yyyy | hh:mm tt Tuesday, 22 August 2006 06:30 AM |
4 | dddd, dd MMMM yyyy | H:mm Tuesday, 22 August 2006 6:30 |
5 | dddd, dd MMMM yyyy | h:mm tt Tuesday, 22 August 2006 6:30 AM |
6 | dddd, dd MMMM yyyy HH:mm:ss | Tuesday, 22 August 2006 06:30:07 |
7 | MM/dd/yyyy HH:mm | 08/22/2006 06:30 |
8 | MM/dd/yyyy hh:mm tt | 08/22/2006 06:30 AM |
9 | MM/dd/yyyy H:mm | 08/22/2006 6:30 |
10 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
10 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
10 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
11 | MM/dd/yyyy HH:mm:ss | 08/22/2006 06:30:07 |
12 | MMMM dd | August 22 |
13 | MMMM dd | August 22 |
14 | yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK | 2006-08-22T06:30:07.7199222-04:00 |
15 | yyyy'-'MM'-'dd'T'HH':'mm':'ss.fffffffK | 2006-08-22T06:30:07.7199222-04:00 |
16 | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' | Tue, 22 Aug 2006 06:30:07 GMT |
17 | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' | Tue, 22 Aug 2006 06:30:07 GMT |
18 | yyyy'-'MM'-'dd'T'HH':'mm':'ss | 2006-08-22T06:30:07 |
19 | HH:mm | 06:30 |
20 | hh:mm tt | 06:30 AM |
21 | H:mm | 6:30 |
22 | h:mm tt | 6:30 AM |
23 | HH:mm:ss | 06:30:07 |
24 | yyyy'-'MM'-'dd HH':'mm':'ss'Z' | 2006-08-22 06:30:07Z |
25 | dddd, dd MMMM yyyy HH:mm:ss | Tuesday, 22 August 2006 06:30:07 |
26 | yyyy MMMM | 2006 August |
27 | yyyy MMMM | 2006 August |
The patterns for DateTime.ToString ( 'd' ) :
0 | MM/dd/yyyy | 08/22/2006 |
The patterns for DateTime.ToString ( 'D' ) :
0 | dddd, dd MMMM yyyy | Tuesday, 22 August 2006 |
The patterns for DateTime.ToString ( 'f' ) :
0 | dddd, dd MMMM yyyy HH:mm | Tuesday, 22 August 2006 06:30 |
1 | dddd, dd MMMM yyyy hh:mm | tt Tuesday, 22 August 2006 06:30 AM |
2 | dddd, dd MMMM yyyy H:mm | Tuesday, 22 August 2006 6:30 |
3 | dddd, dd MMMM yyyy h:mm | tt Tuesday, 22 August 2006 6:30 AM |
The patterns for DateTime.ToString ( 'F' ) :
0 | dddd, dd MMMM yyyy HH:mm:ss | Tuesday, 22 August 2006 06:30:07 |
The patterns for DateTime.ToString ( 'g' ) :
0 | MM/dd/yyyy HH:mm | 08/22/2006 06:30 |
1 | MM/dd/yyyy hh:mm | tt 08/22/2006 06:30 AM |
2 | MM/dd/yyyy H:mm | 08/22/2006 6:30 |
3 | MM/dd/yyyy h:mm tt | 08/22/2006 6:30 AM |
The patterns for DateTime.ToString ( 'G' ) :
0 | MM/dd/yyyy HH:mm:ss | 08/22/2006 06:30:07 |
The patterns for DateTime.ToString ( 'm' ) :
0 | MMMM dd | August 22 |
The patterns for DateTime.ToString ( 'r' ) :
0 | ddd, dd MMM yyyy HH':'mm':'ss 'GMT' | Tue, 22 Aug 2006 06:30:07 GMT |
The patterns for DateTime.ToString ( 's' ) :
0 | yyyy'-'MM'-'dd'T'HH':'mm':'ss | 2006-08-22T06:30:07 |
The patterns for DateTime.ToString ( 'u' ) :
0 | yyyy'-'MM'-'dd HH':'mm':'ss'Z' | 2006-08-22 06:30:07Z |
The patterns for DateTime.ToString ( 'U' ) :
0 | dddd, dd MMMM yyyy HH:mm:ss | Tuesday, 22 August 2006 06:30:07 |
The patterns for DateTime.ToString ( 'y' ) :
0 | yyyy MMMM 2006 August |
Building a custom DateTime.ToString Patterns
d | Represents the day of the month as a number from 1 through 31. A single-digit day is formatted without a leading zero |
dd | Represents the day of the month as a number from 01 through 31. A single-digit day is formatted with a leading zero |
ddd | Represents the abbreviated name of the day of the week (Mon, Tues, Wed etc) |
dddd | Represents the full name of the day of the week (Monday, Tuesday etc) |
h | 12-hour clock hour (e.g. 7) |
hh | 12-hour clock, with a leading 0 (e.g. 07) |
H | 24-hour clock hour (e.g. 19) |
HH | 24-hour clock hour, with a leading 0 (e.g. 19) |
m | Minutes |
mm | Minutes with a leading zero |
M | Month number |
MM | Month number with leading zero |
MMM | Abbreviated Month Name (e.g. Dec) |
MMMM | Full month name (e.g. December) |
s | Seconds |
ss | Seconds with leading zero |
t | Abbreviated AM / PM (e.g. A or P) |
tt | AM / PM (e.g. AM or PM |
y | Year, no leading zero (e.g. 2001 would be 1) |
yy | Year, leadin zero (e.g. 2001 would be 01) |
yyy | Year, (e.g. 2001 would be 2001) |
yyyy | Year, (e.g. 2001 would be 2001) |
K | Represents the time zone information of a date and time value (e.g. +05:00) |
z | With DateTime values, represents the signed offset of the local operating system's time zone from Coordinated Universal Time (UTC), measured in hours. (e.g. +6) |
zz | As z but with leadin zero (e.g. +06) |
zzz | With DateTime values, represents the signed offset of the local operating system's time zone from UTC, measured in hours and minutes. (e.g. +06:00) |
f | Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. |
ff | Represents the two most significant digits of the seconds fraction; that is, it represents the hundredths of a second in a date and time value. |
fff | Represents the three most significant digits of the seconds fraction; that is, it represents the milliseconds in a date and time value. |
ffff | Represents the four most significant digits of the seconds fraction; that is, it represents the ten thousandths of a second in a date and time value. While it is possible to display the ten thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. |
fffff | Represents the five most significant digits of the seconds fraction; that is, it represents the hundred thousandths of a second in a date and time value. While it is possible to display the hundred thousandths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. |
ffffff | Represents the six most significant digits of the seconds fraction; that is, it represents the millionths of a second in a date and time value. While it is possible to display the millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. |
fffffff | Represents the seven most significant digits of the seconds fraction; that is, it represents the ten millionths of a second in a date and time value. While it is possible to display the ten millionths of a second component of a time value, that value may not be meaningful. The precision of date and time values depends on the resolution of the system clock. On Windows NT 3.5 and later, and Windows Vista operating systems, the clock's resolution is approximately 10-15 milliseconds. |
F | Represents the most significant digit of the seconds fraction; that is, it represents the tenths of a second in a date and time value. Nothing is displayed if the digit is zero. |
: | Represents the time separator defined in the current DateTimeFormatInfo..::.TimeSeparator property. This separator is used to differentiate hours, minutes, and seconds. |
/ | Represents the date separator defined in the current DateTimeFormatInfo..::.DateSeparator property. This separator is used to differentiate years, months, and days. |
" | Represents a quoted string (quotation mark). Displays the literal value of any string between two quotation marks ("). Your application should precede each quotation mark with an escape character (\). |
' | Represents a quoted string (apostrophe). Displays the literal value of any string between two apostrophe (') characters. |
%c | Represents the result associated with a c custom format specifier, when the custom date and time format string consists solely of that custom format specifier. That is, to use the d, f, F, h, m, s, t, y, z, H, or M custom format specifier by itself, the application should specify %d, %f, %F, %h, %m, %s, %t, %y, %z, %H, or %M. For more information about using a single format specifier, see Using Single Custom Format Specifiers. |
Easy Convert String to DateTime Formatting with ASP.NET C#
dtnow = System.DateTime.Now; // assign current date
string strdtnow = dtnow.ToString("dd/MM/yyyy").ToString(); // Convert String to DateTime with date Formatting
Sunday, October 10, 2010
Get MAC address of your system with c#.Net
Can convert this code to VB.NET easily.
public string GetMACAddress()
{
ManagementClass mc = new ManagementClass("Win32_NetworkAdapterConfiguration");
ManagementObjectCollection moc = mc.GetInstances();
string MACAddress = String.Empty;
foreach (ManagementObject mo in moc)
{
if (MACAddress == String.Empty) // only return MAC Address from first card
{
if ((bool)mo["IPEnabled"] == true) MACAddress = mo["MacAddress"].ToString();
}
mo.Dispose();
}
MACAddress = MACAddress.Replace(":", "");
return MACAddress;
}
Wednesday, October 06, 2010
How to use CASE function to form conditional expressions?
Here I will describe the function in the SQL with conditional expressions or CASE function in your SQL Query
Execute the following Microsoft SQL Server T-SQL database scripts in Management Studio Query Editor to demonstrate the use of the CASE function to build complex conditional expressions.
How to compare two tables for differences in SQL Server?
-- TEMPLATE - SQL Server T-SQL compare two tables
SELECT Label='Found IN Table1, NOT IN Table2',* FROM
(SELECT * FROM Table1
EXCEPT
SELECT * FROM Table2) x
UNION ALL
SELECT Label='Found IN Table2, NOT IN Table1',* FROM
(SELECT * FROM Table2
EXCEPT
SELECT * FROM Table1) y
SELECT Label='Found IN AW8PP, NOT IN AWPP',* FROM
(SELECT * FROM AdventureWorks2008.Production.Product
EXCEPT
SELECT * FROM AdventureWorks.Production.Product) x
UNION ALL
SELECT Label='Found IN AWPP, NOT IN AW8PP',* FROM
(SELECT * FROM AdventureWorks.Production.Product
EXCEPT
SELECT * FROM AdventureWorks2008.Production.Product) y
GO
-- (0 row(s) affected
------------
How to convert from string to date / datetime?
Here I will explain how to convert string date time into date in MS SQL Server queries with the formats of Date and Time in SQL.
Execute the following T-SQL scripts in Microsoft SQL Server Manangement Studio Query Editor to demonstrate T-SQL convert and cast functions in transforming string date, string time & string datetime data to datetime data type. T-SQL date / datetime functions usage examples are presented as well.
Saturday, August 07, 2010
SQL Pad Left Functionality (Oracle / SQL Server)
This is not uncommon practice. Often times, similar functionality is required when pulling data from the mainframe where “super keys” are paramount. Our good friends at MS have set up SQL Server so that this is universally simple. The code snippet in its basic form looks like this:
Wednesday, August 04, 2010
How to load csv file into a datagrid in VB.net
Load a csv file of any dimension into a datagridview. This example reads a csv file and adds rows and columns to the datagrid as needed. You can specify your own delimiter ("," or ";" or whatever).
Instructions:
Open a new Windows Forms Application and add 1 button, an openfile dialog, a datagridview and a richtextbox to the form. Click the button to browse for a *.csv file to load it into the datagrid.
Replace all the automatically generated code in your project with the code below.
This isn't my code, so all credit goes to the original author whose name I can't recall.
Code:
Public Class Form1 Private FileName As String Private ds As New DataSet() Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'Configure the openfile dialog OpenFileDialog1.Filter = "csv files|; *.csv" OpenFileDialog1.Title = "Select a csv file" OpenFileDialog1.FileName = "" Try With OpenFileDialog1 If .ShowDialog() = DialogResult.OK Then FileName = .FileName 'Set chosen filename as contents of the RichTextBox RichTextBox1.Text = FileName Dim myData4 As DataTable = BuildDataTable(FileName, ";") 'Specify the delimiting character. I work with semicolon delimited files. ds = New DataSet() ds.Tables.Add(myData4) DataGridView1.DataSource = myData4 'Count rows loaded into the datagrid. Useful for looping through the rows Dim totalrows As Integer = DataGridView1.RowCount - 1 MessageBox.Show(totalrows & " rows were loaded into the datagrid!", "www.interloper.nl", MessageBoxButtons.OK, MessageBoxIcon.Information) End If End With Catch End Try End Sub 'FUNCTION: Load csv into datagrid Private Function BuildDataTable(ByVal fileFullPath As String, ByVal separator As Char) As DataTable Dim myTable As DataTable = New DataTable("MyTable") Dim i As Integer Dim myRow As DataRow Dim fieldValues As String() Dim f As IO.File = Nothing Dim myReader As New IO.StreamReader(fileFullPath, System.Text.Encoding.UTF8) 'You might to change the encoding type Try fieldValues = myReader.ReadLine().Split(separator) For i = 0 To fieldValues.Length() - 1 myTable.Columns.Add(New DataColumn("Field" & i)) 'Column headers get Field# as name Next myRow = myTable.NewRow For i = 0 To fieldValues.Length() - 1 myRow.Item(i) = fieldValues(i).ToString Next myTable.Rows.Add(myRow) While myReader.Peek() <> -1 fieldValues = myReader.ReadLine().Split(separator) myRow = myTable.NewRow For i = 0 To fieldValues.Length() - 1 myRow.Item(i) = fieldValues(i).ToString Next myTable.Rows.Add(myRow) End While Catch ex As Exception MsgBox("Error building datatable: " & ex.Message) Return New DataTable("Empty") Finally myReader.Close() End Try Return myTable End Function End Class ------------------------------------------------------- Small Short Code Dim myArray() As String = "asma , tehmina , sumera , sana , sohail"myArray = Split(line, ",") Dim i As Integer dim val as For i = 0 To myArray.Length - 1 val = myArray(i) 'read the value of the items in the array dg.Item(row, column) = val 'place it in the datagrid Next
Monday, August 02, 2010
VB.NET Tab Page Change from code
mainTab.SelectedTab = mainTab.TabPages(0)
mainTab TAB NAME
SelectedTab
Code description:
TabPages(0) = where you want to Jump Index Number ( 0 ,1 , 2 )
Saturday, July 24, 2010
Get Month Name
DateTimeFormatInfo.GetMonthName Method
string strMonth = DateTime.Now.ToString("MMMM")
For the default invariant DateTimeFormatInfo, this method returns a string from the GregorianCalendar:
month | Return Value |
---|---|
1 | "January" |
2 | "February" |
3 | "March" |
4 | "April" |
5 | "May" |
6 | "June" |
7 | "July" |
8 | "August" |
9 | "September" |
10 | "October" |
11 | "November" |
12 | "December" |
13 | "" |
Calendar objects can accommodate calendars with 13 months. For 12-month calendars, the empty string is always returned as the name of the 13th month.
Reff: http://msdn.microsoft.com/en-us/library/d4009dd5%28vs.71%29.aspx
Thursday, July 15, 2010
Counting Parents and Children with Count Distinct
Wednesday, June 16, 2010
How to display arabic numbers in crystal reports
StrArb := Replace (StrArb ,"0" , "٠" );
StrArb := Replace (StrArb ,"1" ,"١" );
StrArb := Replace (StrArb ,"2" ,"٢" );
StrArb := Replace (StrArb ,"3" ,"٣" );
StrArb := Replace (StrArb ,"4" ,"٤" );
StrArb := Replace (StrArb ,"5" ,"٥" );
StrArb := Replace (StrArb ,"6" ,"٦" );
StrArb := Replace (StrArb ,"7" ,"٧" );
StrArb := Replace (StrArb ,"8" ,"٨" );
StrArb := Replace (StrArb ,"9" ,"٩" );
Enter the Formula Name:
STEP 3: WRITE THE FORMULA CODE FOR DISPLAY ARABIC NUMBER IN CRYSTAL REPORT
stringVar StrArb := ToText({ROTT.Aux_f_3});
StrArb := Replace (StrArb ,"0" , "٠" );
StrArb := Replace (StrArb ,"1" ,"١" ); StrArb := Replace (StrArb ,"2" ,"٢" );
StrArb := Replace (StrArb ,"3" ,"٣" );
StrArb := Replace (StrArb ,"4" ,"٤" );
StrArb := Replace (StrArb ,"5" ,"٥" );
StrArb := Replace (StrArb ,"6" ,"٦" );
StrArb := Replace (StrArb ,"7" ,"٧" );
StrArb := Replace (StrArb ,"8" ,"٨" );
StrArb := Replace (StrArb ,"9" ,"٩" ); 1) Save Formula and close the formula workshop window
2) click on Field explorer
3) In Field explorer drag drop your formula on your report
Monday, June 14, 2010
Data Mining: What is Data Mining?
Data Mining: What is Data Mining?
Introduction
Generally, data mining (sometimes called data or knowledge discovery) is the process of analyzing data from different perspectives and summarizing it into useful information - information that can be used to increase revenue, cuts costs, or both. Data mining software is one of a number of analytical tools for analyzing data. It allows users to analyze data from many different dimensions or angles, categorize it, and summarize the relationships identified. Technically, data mining is the process of finding correlations or patterns among dozens of fields in large relational databases.Continuous Innovation
Although data mining is a relatively new term, the technology is not. Companies have used powerful computers to sift through volumes of supermarket scanner data and analyze market research reports for years. However, continuous innovations in computer processing power, disk storage, and statistical software are dramatically increasing the accuracy of analysis while driving down the cost.Example
For example, one Midwest grocery chain used the data mining capacity of Oracle software to analyze local buying patterns. They discovered that when men bought diapers on Thursdays and Saturdays, they also tended to buy beer. Further analysis showed that these shoppers typically did their weekly grocery shopping on Saturdays. On Thursdays, however, they only bought a few items. The retailer concluded that they purchased the beer to have it available for the upcoming weekend. The grocery chain could use this newly discovered information in various ways to increase revenue. For example, they could move the beer display closer to the diaper display. And, they could make sure beer and diapers were sold at full price on Thursdays.Data, Information, and Knowledge
Data
Data are any facts, numbers, or text that can be processed by a computer. Today, organizations are accumulating vast and growing amounts of data in different formats and different databases. This includes:
- operational or transactional data such as, sales, cost, inventory, payroll, and accounting
- nonoperational data, such as industry sales, forecast data, and macro economic data
- meta data - data about the data itself, such as logical database design or data dictionary definitions
Information
The patterns, associations, or relationships among all this data can provide information. For example, analysis of retail point of sale transaction data can yield information on which products are selling and when.
Sunday, June 13, 2010
Displaying Arabic Number. VB.Net
Displaying Arabic Number.
Imports System.Text
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Label1.Text = TextBox1.Text
Label3.Text = ConvertToArabicNumerals(TextBox1.Text)
End Sub
Public Function ConvertToArabicNumerals(ByVal input As String) As String
Dim utf8Encoder As System.Text.UTF8Encoding = New UTF8Encoding()
Dim utf8Decoder As System.Text.Decoder = utf8Encoder.GetDecoder()
Dim convertedChars As New System.Text.StringBuilder()
Dim convertedChar As Char() = New Char(0) {}
Dim bytes As Byte() = New Byte() {217, 160}
Dim inputCharArray As Char() = input.ToCharArray()
For Each c As Char In inputCharArray
If Char.IsDigit(c) Then
bytes(1) = Convert.ToByte(160 + Char.GetNumericValue(c))
utf8Decoder.GetChars(bytes, 0, 2, convertedChar, 0)
convertedChars.Append(convertedChar(0))
Else
convertedChars.Append(c)
End If
Next
Return convertedChars.ToString()
End Function
Wednesday, June 09, 2010
ASP.NET / VB.net Calendar Popup with eworldui
Page Directives:
Calendar 1
<%@ Register TagPrefix="ew" Namespace="eWorld.UI" Assembly="eWorld.UI, Version=1.9.0.0, Culture=neutral, PublicKeyToken=24d65337282035f2" %>
<div>
Calendar 2
<ew:calendarpopup class="tableproptext_az" id="dtExpDate" runat="server" Width="184px" CssClass="tableproptext_az"
ImageUrl="site\images\calendar.png" Height="20px" Font-Names="Tahoma,Arial" ControlDisplay="TextBoxImage"
widht="200">
<WeekdayStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Black" BackColor="White">WeekdayStyle>
<MonthHeaderStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="White" BackColor="Green">MonthHeaderStyle>
<OffMonthStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Gray" BackColor="AntiqueWhite">OffMonthStyle>
<GoToTodayStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Black" BackColor="White">GoToTodayStyle>
<TodayDayStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Black" BackColor="Pink">TodayDayStyle>
<DayHeaderStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="White" BackColor="Navy">DayHeaderStyle>
<WeekendStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Black" BackColor="LightGray">WeekendStyle>
<SelectedDateStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="White" BackColor="Green">SelectedDateStyle>
<ClearDateStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Black" BackColor="White">ClearDateStyle>
<HolidayStyle Font-Size="X-Small" Font-Names="Tahoma,Arial" ForeColor="Black" BackColor="White">HolidayStyle>
ew:calendarpopup>
div>
Reff: www.eworldui.net
Download Link:
Download DLL for calendar popup
------------------------
A demo for this control is located here: View Demo
Download Now!