Enter your email address:


feedburner count
Showing posts with label SQL Server. Show all posts
Showing posts with label SQL Server. Show all posts

T-SQL : How get only Time Part in DateTime value

Labels:

DECLARE @CurrentDate datetime
SET @CurrentDate = '8/3/2006 4:09:00 PM'
SET @CompareDate = '8/3/2006 4:09:00 PM'

Get Time part as nvarchar or char :
Using :
select right(convert(nvarchar,@CurrentDate,120),9)
Or :
SELECT Convert(CHAR(24), @CurrentDate,108)

How to compare only time part in DateTime value , we use DatePart function :


DatePart(hour, @CurrentDate) >= DatePart(hour, @CompareDate) AND
DatePart(minute, @CurrentDate) >= DatePart(minute, @CompareDate) AND
DatePart(second, @CurrentDate) >= DatePart(second, @CompareDate) AND



SQL 2000 - SQL 2005 Database Upgrade : Database Diagrams problem

Labels:

I restored Sql Server database 2005 from Sql Server 2000, then I want to add a new diagram, but when I click "Database Diagrams" there an error message "Database diagram support objects cannot be installed because this database does not have a valid owner. To continue, first use the Files page of the Database Properties dialog box or the ALTER AUTHORIZATION statement to set the database owner to a valid login, then add the database diagram support objects. ". Follow these steps to resolve this problem:
1. Right Click on your database, choose properties
2. Goto the Options Page
3. In the Dropdown at right labeled "Compatibility Level" choose "SQL
Server 2005(90)"
4. Press OK.

The alternating method, you can run sthis store procedure:

EXEC sp_dbcmptlevel 'yourDB', '90';
GO
ALTER AUTHORIZATION ON DATABASE::yourDB TO "yourLogin"
GO
USE [yourDB]
GO
EXECUTE AS USER = N'dbo' REVERT
GO





ASP.NET Today: Smart Delete

Labels:

DetailsView and FormView controls support delete operations and delegate the execution to the underlying data source control. If the data source control is configured to execute the delete operation, all works fine, otherwise an exception is thrown.

The DetailsView generates command buttons automatically and doesn't expose them directly to page code. How can you add a bit of Javascript code to ask for confirmation? Here's the code.

protected void DetailsView1_ItemCreated(object sender, EventArgs e)
{
// Test FooterRow to make sure all rows have been created
if (DetailsView1.FooterRow != null)
{
// The command bar is the last element in the Rows collection
int commandRowIndex = DetailsView1.Rows.Count-1;
DetailsViewRow commandRow = DetailsView1.Rows[commandRowIndex];

// Look for the DELETE button
DataControlFieldCell cell = (DataControlFieldCell) commandRow.Controls[0];
foreach(Control ctl in cell.Controls)
{
LinkButton link = ctl as LinkButton;
if (link != null)
{
if (link.CommandName == "Delete")
{
link.ToolTip =
"Click here to delete";
link.OnClientClick =
"return confirm('Do you really want to delete this record?');";
}
}
}
}

The ItemCreated event doesn't provide any information about the row being created. However, it can be figured out that the footer row is always created and is always the last row to be created. If the FooterRow object is not null, you can conclude that all rows have been created, including the command bar. The command bar is the first row after the data rows and is stored in the Rows collection--it's the last element in the collection. The command bar is a table row (type is DetailsViewRow) and contains a cell (type is DataControlFieldCell). The cell contains as many link buttons (type is DataControlLinkButton) as there are commands. Delete, Edit, New, Update, Cancel are the command names used and useful to identify the right button.


The FormView is fully templated and lets you manually define appearance and behavior of command buttons. If you place a custom button, or want to use a custom command name for a standard button (Edit, New, Delete), here's how to detect the click on the button. You start by adding a handler for ItemCommand. The code below shows how to deal with a custom Delete button that checks if the bound data source control is enabled for deletion before proceeding.

protected void FormView1_ItemCommand(object sender, FormViewCommandEventArgs e)
{
if (e.CommandName == "SmartDelete")
{
IDataSource obj = (IDataSource) FindControl(FormView1.DataSourceID);
DataSourceView view = obj.GetView("DefaultView");
if (!view.CanDelete) {
Response.Write(
"Sorry, you can't delete");
return;
}
else
FormView1.DeleteItem();
}
}