JDev

Code, oracleSeptember 23, 2009 6:11 pm

ALTER SESSION SET CURRENT_SCHEMA = schema

Code, SQL ServerJuly 9, 2009 5:06 pm

Suppose values in your fields contain a period, and you want to return all characters that come before it. This is how you do in SQL Server:

select substring(column1, 1, charindex(’.', column1)-1 )
from myTable

Code, javascriptJune 10, 2009 1:47 pm

Here is a function based on excellent code from Philip M at http://www.codingforums.com/showthread.php?t=168661 that capitalizes the first letter of each word:

function caps(str){
    return str.toLowerCase().replace(/\b[a-z]/g,function(w){return w.toUpperCase()});
}

 

Code, SQL ServerApril 15, 2009 12:48 pm

WHERE datalength(ColumnName)> 0  shows non-empty fields

Code, SQL ServerMarch 9, 2009 9:23 pm

If you have single quotes in your text values, and you need to insert them in a SQL Server database the recommended approach is to use parameterized stored procedures. They will handle single quotes seamlessly.

However, there may be cases when you may need to construct an insert statement without resorting to parameters. In such cases, to handle text that contains single quotes you may have to use the Transact-SQL Replace function:

REPLACE ( string_expression , string_pattern , string_replacement )

An example that escapes single quotes by adding another single quote before it:

Declare @temp as varchar(64)
Set  @temp= (select …  from …)
Set @temp = Replace(@temp, ‘”’,””'’)

In other words, you need 4 single quotes as a second argument, and 6 single quotes as a second argument to escape single quotes.

Code, .NETFebruary 12, 2009 8:18 pm

This solution was found on http://razvan.cosma.name/weblog/index.php?entry=entry090116-161656

private void ExportToExcel(string strFileName, GridView gv)
        {
            Response.ClearContent();
            Response.ContentType = "application/excel";
            Response.AddHeader("content-disposition", "attachment; filename=" + strFileName);
            Response.Charset = "";         
            Response.ContentEncoding = System.Text.Encoding.Unicode;
            Response.BinaryWrite(System.Text.Encoding.Unicode.GetPreamble());
            this.EnableViewState = false;
            System.IO.StringWriter sw = new System.IO.StringWriter();
            HtmlTextWriter htw = new HtmlTextWriter(sw);
            gv.RenderControl(htw);
            Response.Write(sw.ToString());    
            HttpContext.Current.ApplicationInstance.CompleteRequest();
        }

 

 

 

Code, javaFebruary 11, 2009 4:01 am

If you need to find text lines that start with an alphanumeric characters:

String reg ="\\w+";  

In other words, an alphanumeric character that gets repeated 1 or more times.

 To find text lines that start with a whitespace and contain other characters after it, use the following regex:

String  reg = "\\s.+";

 That is, first find a whitespace, then any character repeated 1 or more times.

 

Code, SQL ServerJanuary 29, 2009 7:50 pm

The ‘desc’ command to get a list of table fields that is common in Oracle and MySql will fail in SQL Server. It turns out it is not sql-standard compliant. Instead, SQL Server uses the following command:

sp_columns myTableName

This will display detailed information about table structure.

If you need just individual columns, use the following command:

select column_name, data_type, character_maximum_length, *  
from information_schema.columns
where table_name = ‘myTableName’

order by ordinal_position 

 

.NET, ExcelJanuary 6, 2009 9:31 pm

Here is a discussion of the captioned issue with a solution posted at the end of the page, pointing to a third-party solution.

Code, javaNovember 13, 2008 5:54 pm

Use a Pattern  class from the java.util.regex package to split a long string into separate words in Java.

A Pattern is a compiled representation of a regular expression.

String str = "a     very long   string   possibly with   line breaks  ,  tab   delimiters etc";

Pattern p = Pattern.compile("[,\\s]+");
String[] arr = p.split(str);          

Code, .NETNovember 7, 2008 9:25 pm

 

I use this function found on the stackoverflow site to check whether a string is a number:

return System.Text.RegularExpressions.Regex.IsMatch
         (TextValue, @"^-?\d+([\.]{1}\d*)?$");

 It recognizes integers and decimals. However, it fails on comma separators.

 

More tips at http://c-sharpe.blogspot.com/

Code, VBANovember 3, 2008 4:38 pm

Here is a VBA function that converts a column reference to a column index.

Function ColRef2ColNo(ColRef As String) As Integer    
      ColRef2ColNo = 0
     On Error Resume Next
   ColRef2ColNo = Range(ColRef & "1").Column
End Function

	
 

 

javascriptJuly 23, 2008 12:14 pm

A good explanation of the JavaScript event delegation can found in this SitePoint article.

 

Code, cssJune 30, 2008 5:41 pm

Adjusting the left property will have no effect on the matching elements unless those elements have their CSS position set to relative or absolute. The default CSS position for all block‑level elements is static.

If you put an absolutely positioned box inside a relatively positioned box, it moves with that box. It is absolutely relative!

http://www.wpdfd.com/issues/78/absolutely_relative/ 

Code, javascript, .NETJune 25, 2008 1:36 pm

When you use href=’#’ and provide a JavaScript function for the onclick event, the browser always jumps to the top of the page after executing the JavaScript function. The simple way to avoid the jumping effect is to include a ‘return false’ statement after the call to the JavaScript function. Example:

<a href=’#’ onclick=’fnClick(this); return false;’>Do something </a> 

If you use .NET 1.1, you can set "Smartnavigation=true" in Document properties.