Search..

Thursday, November 5, 2009

Message box in ASP.NET webapplication

We know the importance of user friendly messages, when it comes to developing a windows applications, the application support

MessageBox.show("message goes here");

but this is not the case in web applications as there is no support for displaying a message box with a custom message directly.

So here is an alternative, we can make use of a javascript to display an alert box with the custom message.

To acheive the alert box functionality follow the steps :

1) Create a Alert.cs file in AppCode folder.

2) Copy & Paste the below code in the Alert.cs file

3) you can just call the show() from any .cs file in the project like this Alert.show("message");

using System;
using System.Data;
using System.Configuration;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;

///
/// Summary description for Alert
///

public static class Alert
{
public static void show(string message)
{
string cleanMessage = message.Replace("'", "\\'");
string script = "";
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null && !page.IsClientScriptBlockRegistered("alert"))
{
page.ClientScript.RegisterClientScriptBlock(typeof(Alert), "alert", script);
}

}
}


This is all about displaying custom message.

Wednesday, May 6, 2009

To list all the tables present in a database

This query used to list all the tables present in the database

SELECT name
FROM [servername].[databasename].dbo.sysobjects
WHERE xtype='u' order by name


You can also select the other details like
name, id, xtype, uid,info, status, base_schema_ver replinfo,parent_obj,crdate,ftcatid schema_ver,stats_schema_ver,type, userstat, sysstat, indexdel, refdate,version,deltrig,instrig updtrig,seltrig,category,cache

SELECT *
FROM [servername].[databasename].dbo.sysobjects
WHERE xtype='u'

Friday, April 10, 2009

Problem : we have a table in sql server and we have set a primary key to a column and auto increment is enabled, once u go on adding the records into the table the Identity column value is incremented by one, in case if u want to delete all the records in the table and re-insert the values the Identity column value will start from the previous value but not from zero.

Solution:
To reset the Identity column value we have a command in sql

USE Databasename
GO
DBCC CHECKIDENT ('schema.tablename' , RESEED, 0)
GO


On execution of this command successfully the below message is generated

Checking identity information: current identity value '0', current column value '0'.
DBCC execution completed.