Wednesday, April 30, 2008

Adding Empty Row to a Data Grid

How to add empty row in a datagrid.

* Create and add an empty Row for a Data Table.
* Assign the Datatable as dataSource for the datagrid.
* Bind the datagrid.

#VB.NET

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim dt as new DataTable
dt.rows.add(dt.NewRow())
DataGrid1.DataSource = dt
DataGrid1.DataBind()

End Sub



If we need just a template of a datagrid at runtime means, just bind an empty DataTable like below

#VB.NET

Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

Dim dt as new DataTable
DataGrid1.DataSource = dt
DataGrid1.DataBind()

End Sub

Compare two Dates in SQL Server

The below QUERY can compare two dates in sql server. In that query CONVERT() function is exist. Date value is changed into varchar data type by using CONVERT() function . Here we change the DATETIME data type into varchar. So we got exact date alone. The query as follows....

SELECT *
FROM Login_Attendance
WHERE (DATEDIFF(day, CONVERT(varchar(10), currdate, 101), CONVERT(varchar(10), '4/25/2008', 101)) = 0)

Here,

101----> denotes the required format(mm/dd/yyyy) of the date

For eg:
currdate='4/25/2008 2:23:34 PM'