/*Disable Constraints & Triggers*/
exec sp_MSforeachtable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? DISABLE TRIGGER ALL'
/*Perform delete operation on all table for cleanup*/
exec sp_MSforeachtable 'DELETE ?'
/*Enable Constraints & Triggers again*/
exec sp_MSforeachtable 'ALTER TABLE ? CHECK CONSTRAINT ALL'
exec sp_MSforeachtable 'ALTER TABLE ? ENABLE TRIGGER ALL'
/*Reset Identity on tables with identity column*/
exec sp_MSforeachtable 'IF OBJECTPROPERTY(OBJECT_ID(''?''),
''TableHasIdentity'') = 1 BEGIN DBCC CHECKIDENT (''?'',RESEED,0) END'
Monday, December 29, 2008
Call Validators form javascript
We can able to call the Validator controls form the javascript function
if needed
ValidatorEnable(document.getElementById ('reqItem'), true);
reqItem is the ID of the validator control.
www.codeproject.com
Wednesday, December 24, 2008
lord-krishna
http://www.authorstream.com/presentation/ginga-116274-lord-krishna-190-pictures-education-ppt-powerpoint/
Friday, December 19, 2008
CTE (Common Table Expressions)
A common table expression (CTE) is a temporary named result set that can be referred to by a defining statement.
If the WITH clause for a CTE is not the first statement in the batch, you should delimit it from the preceding statement by placing a semicolon (;) in front of it.
Otherwise some time it will produce an error.
Msg 319, Level 15, State 1, Line 228
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
--If we are having only CTE and no other statements
--it will produce an error.
--Msg 102, Level 15, State 1, Line 29
--Incorrect syntax near ')'.
--SELECT * FROM cte
--A Common Table Expression must be called immediately after stating it.
--If not it will fail
--Otherwise it will produce the error
--Msg 8158, Level 16, State 1, Line 1
--'cte' has more columns than were specified in the column list.
Recurisve CTE
When a CTE refers to itself, it is considered to be recursive.
This is mainly used when hierarchical data is stored in the table.
Default MAXRECURSION is 1000.
SELECT * FROM cteName OPTION (MAXRECURSION 4)
MAXRECURSION OPTION allowed maximum is 32767.
Reference Link
http://jonathanparker.com.au/
http://www.databasejournal.com/
http://www.mssqltips.com/
http://omnibuzz-sql.blogspot.com
Search for the below text in the below link and it is explained well.
Recursive Queries and Common Table Expressions
; WITH( ) AS ( )
If the WITH clause for a CTE is not the first statement in the batch, you should delimit it from the preceding statement by placing a semicolon (;) in front of it.
Otherwise some time it will produce an error.
Msg 319, Level 15, State 1, Line 228
Incorrect syntax near the keyword 'with'. If this statement is a common table expression or an xmlnamespaces clause, the previous statement must be terminated with a semicolon.
;WITH cte AS ( SELECT StationID, Station, Line1, Line2, Line3, Line4, Line5 FROM City1 )
--If we are having only CTE and no other statements
--it will produce an error.
--Msg 102, Level 15, State 1, Line 29
--Incorrect syntax near ')'.
;WITH cte AS ( SELECT StationID, Station, Line1, Line2, Line3, Line4, Line5 FROM City1 )--SELECT * FROM City1
--SELECT * FROM cte
--A Common Table Expression must be called immediately after stating it.
--If not it will fail
;WITH cte (StationID, Station) AS ( SELECT StationID, Station, Line1, Line2, Line3, Line4, Line5 FROM City1 ) SELECT * FROM cte--All columns in the CTE must be in the Column List.
--Otherwise it will produce the error
--Msg 8158, Level 16, State 1, Line 1
--'cte' has more columns than were specified in the column list.
;WITH cte (A, B, C, D, E) AS ( SELECT StationID, Station, Line1, Line2, Line3, Line4, Line5 FROM City1 ) SELECT * FROM cte--But we can give new name for each column in CTE in Column List
Recurisve CTE
When a CTE refers to itself, it is considered to be recursive.
This is mainly used when hierarchical data is stored in the table.
; WITH cteName (column list(optional)) AS ( -- Anchor Query or Anchor Member(AM) UNION ALL --(This is the only thing allowed) -- Recursive Query or Recursive Member (RM). )Defined number of loops
Default MAXRECURSION is 1000.
SELECT * FROM cteName OPTION (MAXRECURSION 4)
MAXRECURSION OPTION allowed maximum is 32767.
Reference Link
http://jonathanparker.com.au/
http://www.databasejournal.com/
http://www.mssqltips.com/
http://omnibuzz-sql.blogspot.com
Search for the below text in the below link and it is explained well.
Recursive Queries and Common Table Expressions
Thursday, December 18, 2008
DataReader to DataTable
public class DataUtils: System.Data.Common.DataAdapter
{
public DataUtils()
{
//
// TODO: Add constructor logic here
//
}
public int FillFromReader( DataTable dataTable, IDataReader dataReader )
{
return this.Fill( dataTable, dataReader );
}
}
How to call
DataUtils _objDataUtils = new DataUtils();
objDataUtils.FillFromReader( dataTable, dr ); //converts a datareader into a datatable
Wednesday, December 17, 2008
SqlParameter
Case 1
SqlParameter[] osqlParam = new SqlParameter[2];
osqlParam[0] = new SqlParameter("@FromCity", SqlDbType.VarChar);
osqlParam[0].Value = _objTubeMap.fromStation;
osqlParam[1] = new SqlParameter("@ToCity", SqlDbType.VarChar);
osqlParam[1].Value = _objTubeMap.toStation;
return SQLHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, "GetStations", osqlParam);
Case2
string[] paramsNames = new string[2] { "@PostTitle", "@PostBody" };
string[] values = new string[2] { TextBox1.Text, Body };
SqlParameter[] parameters = new SqlParameter[2];
for (int i = 0; i < paramsNames.Length; i++)
{
parameters[i] = new SqlParameter();
parameters[i].ParameterName = paramsNames[i];
parameters[i].Value = values[i];
}
SqlParameter[] osqlParam = new SqlParameter[2];
osqlParam[0] = new SqlParameter("@FromCity", SqlDbType.VarChar);
osqlParam[0].Value = _objTubeMap.fromStation;
osqlParam[1] = new SqlParameter("@ToCity", SqlDbType.VarChar);
osqlParam[1].Value = _objTubeMap.toStation;
return SQLHelper.ExecuteReader(connectionString, CommandType.StoredProcedure, "GetStations", osqlParam);
Case2
string[] paramsNames = new string[2] { "@PostTitle", "@PostBody" };
string[] values = new string[2] { TextBox1.Text, Body };
SqlParameter[] parameters = new SqlParameter[2];
for (int i = 0; i < paramsNames.Length; i++)
{
parameters[i] = new SqlParameter();
parameters[i].ParameterName = paramsNames[i];
parameters[i].Value = values[i];
}
Friday, December 5, 2008
AJAX Exceptions
Sys.WebForms.pageRequestManager TimeoutException : the server request timed out
Solve this error by setting the executionTimeout inside ScriptManager
Sys.WebForms.PageRequestManagerParserErrorException: The message received from the
server could not be parsed. Common causes for this error are when the response is
modified by calls to Response.Write(), response filters, HttpModules, or server
trace is enabled.
"Sys.WebForms.PageRequestManagerParserErrorException: The message received from the
server could not be parsed. Common causes for this error are when the response is
modified by calls to Response.Write(), response filters, HttpModules, or server
trace is enabled.".
Solution http://siderite.blogspot.com/
Sys.WebForms.PageRequestManagerParserErrorException:
The message received from the server could not be parsed.
Common causes for the error are when the response
is modified by calls to Response.Write(), response, filters,
HttpModules, or server trace is enabled.
Details: Error parsing near '/div> | '.
Asynchronous (independent) postbacks through the "life cycle" is the same as the
regular pages. The differences occur at the time of rendering. With AJAX,
rendering happens in the partial rendering occurred in the course is in the
UpdatePanel. Render the process of using the "special form" that is only understood
by the JavaScript on the client.
When there are interfensi of the data that is sent to the client
(in the form of a special format that), the special format that will be
damaged and in the end so the client does not understand the longer format of
the data it receives. Parsing process failed and then going over munculah error.
Why it occurs http://weblogs.asp.net/leftslipper/archive/2007/02/26/sys-webforms-pagerequestmanagerparsererrorexception-what-it-is-and-how-to-avoid-it.aspx#b!
Solution http://siderite.blogspot.com/2007/02/aspnet-ajax-and-responsewrite-or.html
protected override void Render(HtmlTextWriter writer)
{
//base.Render(writer);
// render to my own text writer
HtmlTextWriter tw = new HtmlTextWriter(new StringWriter());
base.Render(tw);
/* Code 1 */
//if ( Page != null )
//{
// Page.VerifyRenderingInServerForm ( this );
//}
//base.Render ( tw );
/* Code 1 */
/* Code 2 */
// base.Render(tw); // Code 2 is replaced by code 1
/* Code 2 */
// get the Rendered content of the page
string content = tw.InnerWriter.ToString();
content = RecursiveTranslateAjax(content);
writer.Write(content);
}
private static string RecursiveTranslateAjax(string content)
{
// look for the basic Ajax response syntax
Regex reg = new Regex ( @"^(\d+)\|[^\|]*\|[^\|]*\|", RegexOptions.Singleline );
Match m = reg.Match ( content );
// if found, search deeper, by taking
// into account the length of the html text
if ( m.Success )
{
// custom method to get an integer value
int length = Int ( m.Groups [1] );
reg = new Regex ( @"^(\d+)(\|[^\|]*\|[^\|]*\|)(.{" + length + @"})\|",
RegexOptions.Singleline );
m = reg.Match ( content );
if ( m.Success )
{
string trans = Translate ( m.Groups [3].Value );
return trans.Length + m.Groups [2].Value + trans + "|" +
RecursiveTranslateAjax ( content.Substring ( m.Length ) );
}
}
// if not Ajax, just translate everything,
// it must be a normal PostBack or a string of some sort.
return Translate ( content );
}
private static bool IsNumericVariable(object o)
{
return (o is byte || o is int || o is long || o is float || o is double || o is decimal);
}
public static int Int(object o)
{
if ( o == null ) return 0;
/* const string pattern = "(^[-+]?\\d+(,?\\d*)*\\.?\\d*([Ee][-+]\\d*)?$)|(^[-+]?\\d?(,?\\d*)*\\.\\d+([Ee][-+]\\d*)?$)";
Match numberic = Regex.Match ( o.ToString (), pattern );
// Match numberic = Regex.Match(o.ToString(), "(-\\d+|\\d+)");
// if (IsNumericVariable(o)) return (int)CastDouble(o);
// if (numberic.Success) return (int)CastDouble(o);
if (numberic.Success) return Convert.ToInt32 ( ( (Capture) ( o ) ).Value );
*/
if (IsNumericVariable(o)) return Convert.ToInt32(((Capture)(o)).Value);
string s = o.ToString ();
if ( s == "" ) return 0;
Match m = Regex.Match ( s, "(-\\d+|\\d+)" );
if ( m.Success )
try
{
return Int32.Parse ( m.Groups [0].Value );
}
catch
{
}
return 0;
}
// this method only fixes the weird characters
// but you can put here any string change you would like
// like search and replace some words.
private static string Translate(string content)
{
// Html code all chars that are not ASCII, thus getting rid of strange or Unicode characters
StringBuilder sb = new StringBuilder ();
for ( int c = 0; c <> 127 ) sb.Append ( "&#" + ( (int) content [c] ) + ";" );
else sb.Append ( content [c] );
}
return sb.ToString ();
}
Subscribe to:
Posts (Atom)