เครื่องหมาย ~ มีชื่อว่า Tilde (ออกเสียงว่า ทีล-เด, ทีล-ดา, ทีล-เดอ แล้วแต่จะอ่านแบบไหน แบบเสปน หรือแบบ เนเธอร์แลนด์ หรือแบบ ...) เป็นปุ่มบนคีย์บอร์ดที่ใช้เปลี่ยนภาษา สำหรับคนไทยที่ใช้คอมพิวเตอร์หลายๆ คน ใช้กันจนชิน จนถือเป็นปุ่มที่มีประโยชน์อย่างเดียวคือเปลี่ยนภาษา
แต่เมื่อถึงคราวต้องการพิมพ์ตัว Tilde นี้ออกมาจริงๆ บนหน้าจอคอมฯ แล้ว ก็ต้องกด Shift แล้วกดปุ่ม ~ ตาม ถ้าใน Windows XP ก็ไม่มีปัญหาอะไร แต่พอเจอ Windows 7 แล้ว งงงง!! กดยังไงก็กลายเป็นเปลี่ยนภาษาอยู่ดี สำหรับคนที่ตั้งปุ่ม Ctrl+Shift หรือ Alt+Shift เป็นปุ่มเปลี่ยนภาษาคงไม่เจอเรื่องนี้ แต่ถ้าคนที่ชอบตั้งปุ่ม Tilde นี้เป็นปุ่มเปลี่ยนภาษาแล้วละก็ ...
ถ้าจะพิมพ์เครื่องหมาย Tilde ใน MS Word หรือ Notepad หรือโปรแกรมอื่นใน Windows 7 (ไม่รู้ Vista, Win8 เป็นหรือเปล่า)
ให้กด Shift+ปุ่ม Tilde ค้างไว้ชั่วอึดใจนึง (ประมาณ 1 วินาทีมั้ง) เจ้าตัวอักษร ~ ก็จะโผล่มาครับ แต่ต้องกดในขณะที่เป็นภาษาอังกฤษอยู่นะ ถ้ากดตอนที่คีย์บอร์ดเป็นภาษาไทยอยู่ จะออกมาเป็นเครื่องหมายเปอร์เซนต์ %
โพสต์แนะนำ
วันศุกร์ที่ 25 พฤษภาคม พ.ศ. 2555
วันศุกร์ที่ 11 พฤษภาคม พ.ศ. 2555
.NET Save Excel Error: Old Format or Invalid Type Library
ถ้าใช้ VB หรือ C# .NET สร้าง Excel File แล้วเกิด Error ประมาณนี้
Error: 0x80028018 (-2147647512)
Description: Old Format or Invalid Type Library
อาจจะเกิดปัญหาจาก Locale ของเครื่องไม่ตรงกับ ภาษาในเวอร์ชั่นของ excel เช่น ใช้ Excel เวอร์ชั่นภาษาอังกฤษ แต่ Locale ของเครื่องเป็นภาษาไทย เป็นต้น
การแก้ไขคือ ให้ปรับ Locale ในโค้ดเป็น En-US ก่อน แล้วถึงตามด้วยโค้ดที่ทำงานกับไฟล์ Excel พอทำงานกับ Excel เสร็จ ก็ restore locale กลับ เช่น
'backup ค่า Locale เดิม
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
'ตั้งค่า Locale ใหม่
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
'code ที่ทำงานกับ file Excel
'...
'restore ค่าเดิมกลับ
System.Threading.Thread.CurrentThread.CurrentCulture=oldCI
Error: 0x80028018 (-2147647512)
Description: Old Format or Invalid Type Library
อาจจะเกิดปัญหาจาก Locale ของเครื่องไม่ตรงกับ ภาษาในเวอร์ชั่นของ excel เช่น ใช้ Excel เวอร์ชั่นภาษาอังกฤษ แต่ Locale ของเครื่องเป็นภาษาไทย เป็นต้น
การแก้ไขคือ ให้ปรับ Locale ในโค้ดเป็น En-US ก่อน แล้วถึงตามด้วยโค้ดที่ทำงานกับไฟล์ Excel พอทำงานกับ Excel เสร็จ ก็ restore locale กลับ เช่น
'backup ค่า Locale เดิม
Dim oldCI As System.Globalization.CultureInfo = _
System.Threading.Thread.CurrentThread.CurrentCulture
'ตั้งค่า Locale ใหม่
System.Threading.Thread.CurrentThread.CurrentCulture = _
New System.Globalization.CultureInfo("en-US")
'code ที่ทำงานกับ file Excel
'...
'restore ค่าเดิมกลับ
System.Threading.Thread.CurrentThread.CurrentCulture=oldCI
ฟังก์ชั่น VB.NET เพื่อปรับวันที่ให้สามารถลง Database ได้
ใช้ในการปรับวันที่ให้อยู่ในรูปแบบที่สามารถ Insert / Update ลงดาต้าเบสได้ โดยไม่ต้องสนใจรูปแบบวันที่ของ client และ server ว่าเป็นแบบไหน หรือตรงกันหรือไม่
หลักคือ: รูปแบบวันที่ที่ insert / update ลงใน field ที่เป็น date หรือ datetime ใน Sql Server หรือ Oracle ได้โดยไม่มีปัญหาคือ 'yyyyMMdd' โดยที่ yyyy เป็นปี ค.ศ. MM คือเดือนสองหลัก เช่น มกราคม คือ 01 และสุดท้ายคือ dd เป็นวันที่สองหลัก เช่น วันที่ 3 ก็คือ 03
Private Function ToSQLDate(ByVal pDate As Date) As String
Dim ret As String = ""
If cint(pDate.ToString("yyyy")) > 2500 Then'ถ้าปี มากกว่า 2500 ถือว่าเป็น พ.ศ. ต้องลบ 543
'เอา ปี-543 แล้ว เอามาต่อด้วย เดือน และ วัน
ret &= CStr(cint(pDate.ToString("yyyy")) - 543) & pDate.ToString("MMdd")
Else
'ถ้าเป็น ค.ศ. อยู่แล้ว ก็เอามาจัดให้อยู่ในรูปแบบ yyMMddd
ret = pDate.ToString("yyyyMMdd")
End If
Return ret
End Function
NOTE:
ทดสอบบน
- SQL Server 2000 และสูงกว่า
- Oracle 11g
หลักคือ: รูปแบบวันที่ที่ insert / update ลงใน field ที่เป็น date หรือ datetime ใน Sql Server หรือ Oracle ได้โดยไม่มีปัญหาคือ 'yyyyMMdd' โดยที่ yyyy เป็นปี ค.ศ. MM คือเดือนสองหลัก เช่น มกราคม คือ 01 และสุดท้ายคือ dd เป็นวันที่สองหลัก เช่น วันที่ 3 ก็คือ 03
Private Function ToSQLDate(ByVal pDate As Date) As String
Dim ret As String = ""
If cint(pDate.ToString("yyyy")) > 2500 Then'ถ้าปี มากกว่า 2500 ถือว่าเป็น พ.ศ. ต้องลบ 543
'เอา ปี-543 แล้ว เอามาต่อด้วย เดือน และ วัน
ret &= CStr(cint(pDate.ToString("yyyy")) - 543) & pDate.ToString("MMdd")
Else
'ถ้าเป็น ค.ศ. อยู่แล้ว ก็เอามาจัดให้อยู่ในรูปแบบ yyMMddd
ret = pDate.ToString("yyyyMMdd")
End If
Return ret
End Function
NOTE:
ทดสอบบน
- SQL Server 2000 และสูงกว่า
- Oracle 11g
DateTime.ToString(Pattern)
รูปแบบต่างๆ ของ 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
|
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
The following details the meaning of each pattern character. Note the K and z character.
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.
|
Labels:
Datetime,
Format,
MM/dd/yyyy,
.NET,
String
แปลง Integer เป็น Hex ใน SQL Server (T-SQL)
ขั้นตอนคือ
- แปลง Integer เป็น varbinary
- แปลง varbinary เป็น hex โดยใช้ function master.dbo.fn_varbintohexstr ที่มาพร้อม SQL Server (ตอนที่เขียน เป็น MSSQL2008R2)
master.dbo.fn_varbintohexstr(CONVERT(VARBINARY(8), 1234))
ผลที่ได้คือ 0x000004D2
Oracle Connection String for .NET
Oracle Conn String
Data Source=(DESCRIPTION=(ADDRESS_LIST=(ADDRESS=(PROTOCOL=TCP)(HOST=MyHost)(PORT=MyPort)))(CONNECT_DATA=(SERVER=DEDICATED)(SERVICE_NAME=MyOracleSID)));User Id=myUsername;Password=myPassword;
ส่วนสีแดงคือที่ต้องเปลี่ยนค่าตาม config ของ Oracle
สมัครสมาชิก:
ความคิดเห็น (Atom)