SELECT COLUMN_NAME
FROM INFORMATION_SCHEMA.COLUMNS
WHERE TABLE_SCHEMA = 'database'
AND TABLE_NAME = 'table'
AND COLUMN_KEY = 'PRI'
Thursday, December 24, 2009
Tuesday, December 22, 2009
Monday, December 21, 2009
[.NET] Dataset to Excel, It is very simple!
After hours of Googling finally a very simple yet effective way to convert Dataset into Excel file.
Public Sub dataset2Excel(ByVal sqlStr As String)
'excel file path
Dim excelPath As String = ""
excelPath = Server.MapPath("").Replace("\", "") & "\\Sheet1.xls"
'convertion to string
ds = objdb.ExeQuery(sqlStr, "NICEPMData")
Dim grid As New System.Web.UI.WebControls.DataGrid()
grid.HeaderStyle.Font.Bold = True
grid.DataSource = ds
grid.DataBind()
Dim sw As New StreamWriter(excelPath)
Dim hw As New System.Web.UI.HtmlTextWriter(sw)
grid.RenderControl(hw)
End Sub
Cheers!!
Public Sub dataset2Excel(ByVal sqlStr As String)
'excel file path
Dim excelPath As String = ""
excelPath = Server.MapPath("
'convertion to string
ds = objdb.ExeQuery(sqlStr, "NICEPMData")
Dim grid As New System.Web.UI.WebControls.DataGrid()
grid.HeaderStyle.Font.Bold = True
grid.DataSource = ds
grid.DataBind()
Dim sw As New StreamWriter(excelPath)
Dim hw As New System.Web.UI.HtmlTextWriter(sw)
grid.RenderControl(hw)
End Sub
Cheers!!
Sunday, December 20, 2009
[.NET] How To Create an Excel Macro by Using Automation from Visual Basic .NET
Add COM references:
Microsoft Excel <8.0> Object Library, (optional)
Microsoft Office <8.0> Object Library, and
Microsoft Visual Basic for Applications Extensibility Library
NOTE: version must be the same
Please refer to http://support.microsoft.com/kb/303871
Microsoft Excel <8.0> Object Library, (optional)
Microsoft Office <8.0> Object Library, and
Microsoft Visual Basic for Applications Extensibility Library
NOTE: version must be the same
Please refer to http://support.microsoft.com/kb/303871
[.NET] Reading any text base file
Sample of reading any text base file. Text base means like *.txt, *.js, *.css, etc.
Imports System.IO
...
...
DimFullPath As String
Dim jspath As String = Server.MapPath("folder").Replace("\folder", "") & "\textfile.txt"
...
...
Public Function readFile(ByVal FullPath As String) As String
Dim strContents As String
Dim objReader As StreamReader
Try
objReader = New StreamReader(FullPath)
strContents = objReader.ReadToEnd()
objReader.Close()
readFile = strContents
Catch Ex As Exception
readFile = "read file error"
End Try
End Function
Imports System.IO
...
...
DimFullPath As String
Dim jspath As String = Server.MapPath("folder").Replace("\folder", "") & "\textfile.txt"
...
...
Public Function readFile(ByVal FullPath As String) As String
Dim strContents As String
Dim objReader As StreamReader
Try
objReader = New StreamReader(FullPath)
strContents = objReader.ReadToEnd()
objReader.Close()
readFile = strContents
Catch Ex As Exception
readFile = "read file error"
End Try
End Function
Monday, December 14, 2009
[CSS] Center the web page compatibility for Firefox & IE
* inside the css file is:
body {
text-align: -moz-center;
}
* inside the body tag is:
<@!--[if gte IE 7.0]@>
<@style type="text/css"@>
body {
text-align: center;
}
@style@>
<@![endif]--@>
NOTE: remove the @ character to get the code
body {
text-align: -moz-center;
}
* inside the body tag is:
<@!--[if gte IE 7.0]@>
<@style type="text/css"@>
body {
text-align: center;
}
@style@>
<@![endif]--@>
NOTE: remove the @ character to get the code
[MSSQL] To view table fields information
There are 2 way to view table field information.
1. select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='table name'
* the field is in order according to the table
* have more information about the table
2. select * from table_field_name where table_name='table name'
* the field is not in order according to the table
* less information about the table
create view table_field_name as
SELECT
table_name=sysobjects.name, column_name=syscolumns.name,
datatype=systypes.name, length=syscolumns.length
FROM sysobjects
JOIN syscolumns ON sysobjects.id=syscolumns.id
JOIN systypes ON syscolumns.xtype=systypes.xtype
WHERE sysobjects.xtype='U'
1. select * from INFORMATION_SCHEMA.COLUMNS where TABLE_NAME='table name'
* the field is in order according to the table
* have more information about the table
2. select * from table_field_name where table_name='table name'
* the field is not in order according to the table
* less information about the table
create view table_field_name as
SELECT
table_name=sysobjects.name, column_name=syscolumns.name,
datatype=systypes.name, length=syscolumns.length
FROM sysobjects
JOIN syscolumns ON sysobjects.id=syscolumns.id
JOIN systypes ON syscolumns.xtype=systypes.xtype
WHERE sysobjects.xtype='U'
Subscribe to:
Posts (Atom)