Search


Saturday, April 19, 2008

drawing custom border

http://www.codeplex.com/Wiki/View.aspx?ProjectName=CustomerBorderForm

Thursday, April 17, 2008

Tuesday, April 15, 2008

Windows Forms FAQ Link

http://www.syncfusion.com/FAQ/windowsforms/default.aspx#44

All about Datagrid manipulation ( windows application C#)

5.1 How can I programatically set the rowheight of a row in my DataGrid?
5.2 How can I autosize the rowheights in my datagrid?
5.3 How do I prevent sorting a single column in my DataGrid?
5.4 How do I programmatically select a row in DataGrid?
5.5 How can I translate a point to a cell in the datagrid?
5.6 I lost the settings in my DataGrid set during design-time?
5.7 How do I prevent a click into the grid highlighting a cell?
5.8 How do I prevent the datagrid from displaying its append row (the row at the end with an asterisk)?
5.9 How can I put a combobox in a column of a datagrid?
5.10 How can I catch a double-click into a column header cell?
5.11 How can I select the entire row when the user clicks on a cell in the row?
5.12 How can I get text from a column header in a MouseUp event?
5.13 How do I hide a column?
5.14 How do I color a individual cell depending upon its value or some external method?
5.15 How can I put a checkbox in a column of my DataGrid?
5.16 How can I restrict the keystrokes that will be accepted in a column of my datagrid?
5.17 How do I make a field auto increment as new rows are added to my datagrid?
5.18 How can I prevent a particular cell from being editable?
5.19 How do I move columns in a datagrid?
5.20 How can I do cell by cell validation in a datagrid?
5.21 How do I programmatically determine the selected rows in a datagrid?
5.22 How can I move rows by dragging the row header cell?
5.23 I want to do custom handling of special keys such as the Tab key or F2 in the TextBox of a column in the DataGrid. How do I subclass this TextBox to get at it virtual members?
5.24 How can I have a column of icons in my datagrid?
5.25 How can I tell if the current row has changed and whether I am on the AddNew row or not?
5.26 How do I hide the gridlines or set them to a particular color?
5.27 How can I get the selected text in an active gridcell?
5.28 How do I determine whether a checkbox in my datagrid is checked or not?
5.29 How can I bind the datagrid to a datasource without using any wizards?
5.30 How can I bind two datagrids in a Master-Detail relationship?
5.31 How do I get the row or column that has been clicked on?
5.32 How do I add an unbound column to my bound datagrid?
5.33 How do I get the row and column of the current cell in my datagrid?
5.34 How can I prevent the Enter key from moving to the next cell when the user is actively editing the cell and presses Enter?
5.35 How do I set the width of a column in my DataGrid?
5.36 How can I implement OLE Drag & Drop between a DataGrid and another OLE DnD object that supports the Text format?
5.37 How can I make my DataGrid support a single select mode, and not the default multiselect mode?
5.38 How can I get celltips or tooltips to vary from cell to cell in my DataGrid?
5.39 How can I get notification of the changing of a value in a column of comboboxes within my datagrid?
5.40 How can I make the datagrid have no currentcell?
5.41 How can I make my grid never have an active edit cell and always select whole rows (as in a browser-type grid)?
5.42 I have hidden (column width = 0) columns on the right side of my datagrid, but tabbing does not work properly. How can I get tabbing to work?
5.43 How can I get the number of rows in my DataGrid?
5.44 How do I format a date column in a datagrid?
5.45 How can I change the width of the row headers or hide them?
5.46 How do I catch a doubleclick in my datagrid?
5.47 How can I make my last column wide enough to exactly occupy all the client area of the datagrid?
5.48 How can I prevent my user from sizing columns in my datagrid?
5.49 How can I catch the bool values changing in a DataGridBoolColumn?
5.50 When I click on a row header, the row is selected and no cell is active. How can I do this programmatically?
5.51 How can I force the vertical scrollbar in my DataGrid to always be visible?
5.52 How can I autosize a column in my datagrid?
5.53 How can I get rid of the error icon that appears when there is an editing error?
5.54 How do I find the top-left visible cell in a datagrid?
5.55 I want to display negative values with a CR suffix, instead of a minus sign. How can I perform custom formatting on the cells in my datagrid?
5.56 I want to do sort of a database join of two tables. How can I use data from two DataTables in a single DataGrid?
5.57 How do I display a column of buttons such as pushbuttons or combobox buttons?
5.58 How can I put up a confirmation question when the user tries to delete a row in the datagrid by clicking on the row header and pressing the Delete key?
5.59 How can I enable column selections in my datagrid?
5.60 How do I programmatically scroll the datagrid to a particular row?
5.61 How can I place text in the rowheader column of my datagrid?
5.62 How do I set default values for new rows in my datagrid?
5.63 How do I iterate through all the rows and columns in my datagrid?
5.64 How can I specially color only the currentcell of my readonly datagrid?
5.65 How can I make the Enter Key behave like the Tab Key and move to the next cell?
5.66 How do I use the DataColumn.Expression property to add a computed/combined column to my datagrid?
5.67 How can I change the font used in a grid cell on a cell by cell or row by row basis?
5.68 How can I use a mouse to select cell ranges in my datagrid?
5.69 How can I control the cursor over my DataGrid?
5.70 How can I programatically add and remove columns in my DataGrid without modifying the DataTable datasource?
5.71 How can I have a column of bitmaps in a DataGrid?
5.72 How can I add my custom columnstyles to the designer so I can use them in my DataGrid at design time?
5.73 After scrolling with the mouse wheel on a selected row in a DataGrid I cannot get it back into view. Is there a work around?
5.74 How can I make the DataGrid column be blank and not display (null) as the default value?
5.75 How can I add a DateTimePicker column style to the DataGrid?
5.76 How do I determine the DataGridTableStyle MappingName that should used for a DataGrid to make sure the grid uses my tablestyle?
5.77 I have a derived DataGridColumnStyle. From within my Paint override, how can I get at other values in the DataGrid?
5.78 How do I retrieve the current row from a DataTable bound to a DataGrid after the grid has been sorted?
5.79 How can I catch when the user clicks off the grid, say to close the form?
5.80 How can I get a CheckBox column in a DataGrid to react to the first click?
5.81 How can I use events to restrict key input to grid cells?
5.82 How can I format columns in my DataGrid without explicitly adding DataGridColumnStyles?
5.83 How can I auto-adjust keyboard input? For example, make typing 12312002 be taken as a valid date, 12/31/2002.
5.84 Can I display the rows in my datagrid in a free-form layout using textboxes on a panel?
5.85 How can I tell whether a scrollbar is visible in my DataGrid is visible?
5.86 How do I autosize the columns in my DataGrid so they always fill the the grid's client area?
5.87 How can I prevent all the cells in my DataGrid from being edited without deriving GridColumnStyle?
5.88 How can I prevent the plus-minus icon that appears next to the row header when I have a datagrid displayed bound to a datasource that has a relation defined?
5.89 How can I display master-details-details in three separate grids?
5.90 In my datagrid, if I press tab to enter a column using a derived columnstyle, the column does not receive focus. Why?
5.91 How can I detect when a cell starts being edited, not when it becomes current?

Monday, April 7, 2008

Using CAST and CONVERT with datetime data

SELECT
  GETDATE() AS UnconvertedDateTime,
  CAST(GETDATE() AS nvarchar(30)) AS UsingCast,
  CONVERT(nvarchar(30), GETDATE(), 126) AS UsingConvertTo_ISO8601  ;
GO

Here is the result set.

UnconvertedDateTime UsingCast UsingConvertTo_ISO8601

----------------------- ------------------------------ ------------------------------

2006-04-18 09:58:04.570 Apr 18 2006 9:58AM 2006-04-18T09:58:04.570

http://msdn2.microsoft.com/en-us/library/ms187928.aspx

ntext and varchar can't use operators: =, != , <, >

problem: The data types ntext and varchar are incompatible in the equal to operator. solution use LIKE or PATINDEX, for

Sunday, April 6, 2008

careful with javascript - [common mistakes in javascript]

some of the common mistakes that we make while writing script. Use more "var" Reduce scopes Careful with DOM element concatenation Avoid using your own method while there is one Avoid using Array.length in a loop Avoid String concatenation, use Array instead Introduce function delegates Introduce DOM elements and function caching Problem with switch http://www.codeproject.com/KB/ajax/AspNetAjaxBestPractices.aspx

Browse with proxy

to browse web that have been blocked by isp provider http://bypass.connectionproxy.com http://www.pagewash.com to access youtube in school / any other facilitis that block youtube: http://www.youtubeproxy.co.uk/

Friday, April 4, 2008

Pattern Matching

pattern matching: • % (percent mark): This wildcard represents zero to many characters. For example, WHERE title LIKE '%C# 2008%' finds all book titles containing the text “C# 2008,” regardless of where in the title that text occurs—at the beginning, middle, or end. In this case, book titles such as “C# 2008: An Introduction,” “Accelerated C# 2008,” and “Beginning C# 2008 Databases” will be listed. • _ (underscore): A single underscore represents any single character. By using this wildcard character, you can be very specific in your search about the character length of the data you seek. For example, WHERE au_fname LIKE '_ean' finds all the first names that consist of four letters and that end with “ean” (Dean, Sean, and so on). WHERE au_fname LIKE 'a___n' finds all the first names that begin with “a” and end with “n” and have any other three characters in between, for example, allan, amman, aryan, and so on. • [ ] (square brackets): These specify any single character within the specified range, such as [a-f], or set, such as [abcdef] or even [adf]. For example, WHERE au_lname LIKE '[C-K]arsen' finds author last names ending with “arsen” and starting with any single character between “C” and “K,” such as Carsen, Darsen, Larsen, Karsen, and so on. • [^] (square brackets and caret): These specify any single character not within the specified range, such as [^a-f], or set, such as [^abcdef]. For example, WHERE au_lname LIKE 'de[^l]%' retrieves all author last names starting with “de,” but the following letter cannot be “l.”

Relational Database Management System (RDMS) advantages

RDBMSs offer various benefits by controlling the following: • Redundancy: RDBMSs prevent having multiple duplicate copies of the same data, which takes up disk space unnecessarily. • Inconsistency: Each redundant set of data may no longer agree with other sets of the same data. When an RDBMS removes redundancy, inconsistency cannot occur. • Data integrity: Data values stored in the database must satisfy certain types of consistency constraints. (We’ll discuss this benefit in more detail in the section “Understanding Data Integrity” later in this chapter.) • Data atomicity: In event of a failure, data is restored to the consistent state it existed in prior to the failure. For example, fund transfer activity must be atomic. (We cover the fund transfer activity and atomicity in more detail in Chapter 8.) • Access anomalies: RDBMSs prevent more than one user from updating the same data simultaneously; such concurrent updates may result in inconsistent data. • Data security: Not every user of the database system should be able to access all the data. Security refers to the protection of data against any unauthorized access. • Transaction processing: A transaction is a sequence of database operations that represents a logical unit of work. In RDBMSs, a transaction either commits all the changes or rolls back all the actions performed till the point at which failure occurred. • Recovery: Recovery features ensure that data is reorganized into a consistent state after a transaction fails. • Storage management: RDBMSs provide a mechanism for data storage management. The internal schema defines how data should be stored

Advantages LinQ (ADO.NET)

Assume you have deployed the framework 2.0 code into production along with the database, which has the column names as specified in the select query. Later, the database administrator (DBA) decides to change the column names in all the tables to implement new database policies: he modifies the employees table and changes the firstname column to EmployeeFirstName and the lastname column to EmployeeLastName. After these database changes are made, the only way to prevent the application from breaking is by modifying all the code segments in source code that refers to the firstname and lastname columns, rebuild, retest, and deploy the whole application again. Though on the surface it seems not so difficult to make such changes, if you factor in the possibility that there might be many database-related code segments that require modification of the column names according to the new column naming scheme, this can end up being a tedious and difficult approach to upgrade an application so it can work with the modified database.

Web config notes for ASP website ( password rule config, max upload file, deny annon user to access specific pages

add additional setting: add: <appSettings> <add key="SiteName" value="yoursitename"/> </appSettings> to change default annoying password rule in ASP.Net (web.config): overview: we will delete a provider named AspNetSqlMembershipProvider then we add new requirements: minRequiredPasswordLength="4", minRequiredNonalphanumericCharacters="0", and passwordStrengthRegularExpression="". means that, we can set password: min 4 chars, no non-alphanumeric needed and no rule for expression. add this code below <system.web> <membership> <providers> <remove name="AspNetSqlMembershipProvider"/> <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider, System.Web, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" connectionStringName="LocalSqlServer" enablePasswordRetrieval="false" enablePasswordReset="true" requiresQuestionAndAnswer="true" applicationName="/" requiresUniqueEmail="false" passwordFormat="Hashed" maxInvalidPasswordAttempts="5"passwordAttemptWindow="10" minRequiredPasswordLength="4" minRequiredNonalphanumericCharacters="0" passwordStrengthRegularExpression=""/> </providers> </membership> change maximum file upload: 8192 KB. add below <system.web> <httpRuntime maxRequestLength="8192"></httpRuntime> deny annon user to access specific pages: add the following in tag <configuration> and after tag <appSettings> <location path="page1.aspx"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> <location path="page2.aspx"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location> <location path="page3.aspx"> <system.web> <authorization> <deny users="?"/> </authorization> </system.web> </location>

Thursday, April 3, 2008

try catch in sql

TRY...CATCH (Transact-SQL) Syntax: BEGIN TRY { sql_statement | statement_block } END TRY BEGIN CATCH [ { sql_statement | statement_block } ] END CATCH [ ; ] http://msdn2.microsoft.com/en-us/library/ms175976.aspx

NVARCHAR versus VARCHAR

NVARCHAR versus VARCHAR

SQL Server provides both datatypes to store character information. For the most part the two datatypes are identical in how you would work with them within SQL Server or from an application. The difference is that nvarchar is used to store unicode data, which is used to store multilingual data in your database tables. Other languages have an extended set of character codes that need to be saved and this datatype allows for this extension. If your database will not be storing multilingual data you should use the varchar datatype instead. The reason for this is that nvarchar takes twice as much space as varchar, this is because of the need to store the extended character codes for other languages

How to merge 2 database

Use SQL server import and export Wizard: - go to database name on Object Explorer - right click on the database name - Task -> Export Data.. -> next -> choose source -> choose destenation - just follow the instruction ~

Asp control Hyperlink

<asp:HyperLink id="value" Runat="Server" ImageUrl="url" NavigateUrl="url" Target="_blank|_self|_top|_parent|framename" Text="string" property="value" Style="CSS style settings..." /> more: http://msconline.maconstate.edu/tutorials/ASPNET20/default.htm

Reference for special char in HTML

character references:
&#x9; for tab,
&#x20; for space,
&#xa0; for non-breaking space.
&lt; for < &gt; for >

for more
http://www.cs.tut.fi/~jkorpela/html/guide/entities.html

Special Characters Reference Sheet

Simply place the Name Code or Color Code in your HTML document where you would like the special character to show up.
Name Code  Number Code  Glyph  Description
&lsquo;   ‘    left single quote
&rsquo;   ’    right single quote
&sbquo;   ‚    single low-9 quote
&ldquo;   “    left double quote
&rdquo;   ”    right double quote
&bdquo;   „    double low-9 quote
&dagger;   †    dagger
&Dagger;   ‡    double dagger
&permil;   ‰    per mill sign
&lsaquo;   ‹    single left-pointing angle quote
&rsaquo;   ›    single right-pointing angle quote
&spades;   ♠    black spade suit
&clubs;   ♣    black club suit
&hearts;   ♥    black heart suit
&larr;   ←    leftward arrow
&uarr;   ↑    upward arrow
&rarr;   →    rightward arrow
&darr;   ↓    downward arrow
&trade;   ™    trademark sign

Name Code  Number Code  Glyph  Description
 &#09;   horizontal tab
 &#10;   line feed
 &#32;   space
 &#33;  !    exclamation mark
&quot;  &#34;  "    double quotation mark
 &#35;  #    number sign
 &#36;  $    dollar sign
 &#37;  %    percent sign
&amp;  &#38;  &    ampersand
 &#39;  '    apostrophe
 &#40;  (    left parenthesis
 &#41;  )    right parenthesis
 &#42;  *    asterisk
 &#43;  +    plus sign
 &#44;  ,    comma
 &#45;  -    hyphen
 &#46;  .    period

Name Code  Number Code  Glyph  Description
&frasl;  &#47;  /    slash
 &#48;-
&#57;   digits 0-9
 &#58;  :    colon
 &#59;  ;    semicolon
&lt;  &#60;  <    less-than sign
 &#61;  =    equals sign
&gt;  &#62;  >    greater-than sign
 &#63;  ?    question mark
 &#64;  @    at sign
 &#65;-
&#90;   uppercase letters A-Z
 &#91;  [    left square bracket
 &#92;  \    backslash
 &#93;  ]    right square bracket
 &#94;  ^    caret
 &#95;  _    horizontal bar (underscore)
 &#96;  `    grave accent
 &#97;-
&#122;   lowercase letters a-z
 &#123;  {    left curly brace
 &#124;  |    vertical bar

Name Code  Number Code  Glyph  Description
 &#125;  }    right curly brace
 &#126;  ~    tilde
&ndash;  &#150;  –    en dash
&mdash;  &#151;  —    em dash
&nbsp;  &#160;       nonbreaking space
&iexcl;  &#161;  ¡    inverted exclamation
&cent;  &#162;  ¢    cent sign
&pound;  &#163;  £    pound sterling
&curren;  &#164;  ¤    general currency sign
&yen;  &#165;  ¥    yen sign
&brvbar; or &brkbar;  &#166;  ¦    broken vertical bar
&sect;  &#167;  §    section sign
&uml; or &die;  &#168;  ¨    umlaut
&copy;  &#169;  ©    copyright
&ordf;  &#170;  ª    feminine ordinal
&laquo;  &#171;  «    left angle quote
&not;  &#172;  ¬    not sign
&shy;  &#173;  ­    soft hyphen
&reg;  &#174;  ®    registered trademark
&macr; or &hibar;  &#175;  ¯    macron accent

Name Code  Number Code  Glyph  Description
&deg;  &#176;  °    degree sign
&plusmn;  &#177;  ±    plus or minus
&sup2;  &#178;  ²    superscript two
&sup3;  &#179;  ³    superscript three
&acute;  &#180;  ´    acute accent
&micro;  &#181;  µ    micro sign
&para;  &#182;  ¶    paragraph sign
&middot;  &#183;  ·    middle dot
&cedil;  &#184;  ¸    cedilla
&sup1;  &#185;  ¹    superscript one
&ordm;  &#186;  º    masculine ordinal
&raquo;  &#187;  »    right angle quote
&frac14;  &#188;  ¼    one-fourth
&frac12;  &#189;  ½    one-half
&frac34;  &#190;  ¾    three-fourths
&iquest;  &#191;  ¿    inverted question mark
&Agrave;  &#192;  À    uppercase A, grave accent
&Aacute;  &#193;  Á    uppercase A, acute accent
&Acirc;  &#194;  Â    uppercase A, circumflex accent

Name Code  Number Code  Glyph  Description
&Atilde;  &#195;  Ã    uppercase A, tilde
&Auml;  &#196;  Ä    uppercase A, umlaut
&Aring;  &#197;  Å    uppercase A, ring
&AElig;  &#198;  Æ    uppercase AE
&Ccedil;  &#199;  Ç    uppercase C, cedilla
&Egrave;  &#200;  È    uppercase E, grave accent
&Eacute;  &#201;  É    uppercase E, acute accent
&Ecirc;  &#202;  Ê    uppercase E, circumflex accent
&Euml;  &#203;  Ë    uppercase E, umlaut
&Igrave;  &#204;  Ì    uppercase I, grave accent
&Iacute;  &#205;  Í    uppercase I, acute accent
&Icirc;  &#206;  Î    uppercase I, circumflex accent
&Iuml;  &#207;  Ï    uppercase I, umlaut
&ETH;  &#208;  Ð    uppercase Eth, Icelandic
&Ntilde;  &#209;  Ñ    uppercase N, tilde
&Ograve;  &#210;  Ò    uppercase O, grave accent
&Oacute;  &#211;  Ó    uppercase O, acute accent
&Ocirc;  &#212;  Ô    uppercase O, circumflex accent
&Otilde;  &#213;  Õ    uppercase O, tilde

Name Code  Number Code  Glyph  Description
&Ouml;  &#214;  Ö    uppercase O, umlaut
&times;  &#215;  ×    multiplication sign
&Oslash;  &#216;  Ø    uppercase O, slash
&Ugrave;  &#217;  Ù    uppercase U, grave accent
&Uacute;  &#218;  Ú    uppercase U, acute accent
&Ucirc;  &#219;  Û    uppercase U, circumflex accent
&Uuml;  &#220;  Ü    uppercase U, umlaut
&Yacute;  &#221;  Ý    uppercase Y, acute accent
&THORN;  &#222;  Þ    uppercase THORN, Icelandic
&szlig;  &#223;  ß    lowercase sharps, German
&agrave;  &#224;  à    lowercase a, grave accent
&aacute;  &#225;  á    lowercase a, acute accent
&acirc;  &#226;  â    lowercase a, circumflex accent
&atilde;  &#227;  ã    lowercase a, tilde
&auml;  &#228;  ä    lowercase a, umlaut
&aring;  &#229;  å    lowercase a, ring
&aelig;  &#230;  æ    lowercase ae
&ccedil;  &#231;  ç    lowercase c, cedilla
&egrave;  &#232;  è    lowercase e, grave accent

Name Code  Number Code  Glyph  Description
&eacute;  &#233;  é    lowercase e, acute accent
&ecirc;  &#234;  ê    lowercase e, circumflex accent
&euml;  &#235;  ë    lowercase e, umlaut
&igrave;  &#236;  ì    lowercase i, grave accent
&iacute;  &#237;  í    lowercase i, acute accent
&icirc;  &#238;  î    lowercase i, circumflex accent
&iuml;  &#239;  ï    lowercase i, umlaut
&eth;  &#240;  ð    lowercase eth, Icelandic
&ntilde;  &#241;  ñ    lowercase n, tilde
&ograve;  &#242;  ò    lowercase o, grave accent
&oacute;  &#243;  ó    lowercase o, acute accent
&ocirc;  &#244;  ô    lowercase o, circumflex accent
&otilde;  &#245;  õ    lowercase o, tilde
&ouml;  &#246;  ö    lowercase o, umlaut
&divide;  &#247;  ÷    division sign
&oslash;  &#248;  ø    lowercase o, slash
&ugrave;  &#249;  ù    lowercase u, grave accent
&uacute;  &#250;  ú    lowercase u, acute accent
&ucirc;  &#251;  û    lowercase u, circumflex accent

Name Code  Number Code  Glyph  Description
&uuml;  &#252;  ü    lowercase u, umlaut
&yacute;  &#253;  ý    lowercase y, acute accent
&thorn;  &#254;  þ    lowercase thorn, Icelandic
&yuml;  &#255;  ÿ    lowercase y, umlaut

what is ORM ? =.=

Object-Relational Mapping (aka ORM, O/RM, and O/R mapping) is a programming technique for converting data between incompatible type systems in relational databases and object-oriented programming languages. This creates, in effect, a "virtual object database" which can be used from within the programming language. There are both free and commercial packages available that perform object-relational mapping, although some programmers opt to create their own ORM tools. more detail: http://en.wikipedia.org/wiki/Object-relational_mapping

LinQ to SQL

before: string query = “SELECT * FROM Products WHERE categoryId = 3”; SqlCommand command = new SqlCommand(); command.CommandText = query; there might be: - runtime error in query... C# can't detect if we spell fron for FROM Thus, with LINQ: SomeDataContext database = new SomeDataContext(); List products = from p in database.Products where p.Price > 300 && p.CategoryId == 3 select p; OR with new C# 3.0 feature lambda expression '=>' SomeDataContext database = new SomeDataContext(); Category aCategory = database.Categories.Single(c => c.Id == 7); c => c.Id == 7 is lambda expression which means to get some c as category where id of c is 7

merging 2 tables each containing the same columns in sql

I have two tables, each containing the same columns: one containing 1000 rows and one with 800 rows. How can I create a third table which is a merge of the other two and ensuring there are no duplicates === Insert into table3 select * from table1 union select * from table2 === if there are no duplicate use: unionall

Wednesday, April 2, 2008

Unpacking Lists in a Table

problem example:
CREATE PROCEDURE get_product_names @ids varchar(50) AS
SELECT ProductID, ProductName
FROM   Northwind..Products
WHERE  ProductID IN (@ids)

above procedure will not work..

solution:

CREATE FUNCTION iter_charlist_to_tbl
                (@list      nvarchar(MAX),
                 @delimiter nchar(1) = N',')
     RETURNS @tbl TABLE (listpos int IDENTITY(1, 1) NOT NULL,
                         str     varchar(4000)      NOT NULL,
                         nstr    nvarchar(2000)     NOT NULL) AS

BEGIN
  DECLARE @endpos   int,
          @startpos int,
          @textpos  int,
          @chunklen smallint,
          @tmpstr   nvarchar(4000),
          @leftover nvarchar(4000),
          @tmpval   nvarchar(4000)

  SET @textpos = 1
  SET @leftover = ''
  WHILE @textpos <= datalength(@list) / 2
  BEGIN
     SET @chunklen = 4000 - datalength(@leftover) / 2
     SET @tmpstr = @leftover + substring(@list, @textpos, @chunklen)
     SET @textpos = @textpos + @chunklen

     SET @startpos = 0
     SET @endpos = charindex(@delimiter COLLATE Slovenian_BIN2, @tmpstr)

     WHILE @endpos > 0
     BEGIN
        SET @tmpval = ltrim(rtrim(substring(@tmpstr, @startpos + 1,
                                            @endpos - @startpos - 1)))
        INSERT @tbl (str, nstr) VALUES(@tmpval, @tmpval)
        SET @startpos = @endpos
        SET @endpos = charindex(@delimiter COLLATE Slovenian_BIN2,
                                @tmpstr, @startpos + 1)
     END

     SET @leftover = right(@tmpstr, datalength(@tmpstr) / 2 - @startpos)
  END

  INSERT @tbl(str, nstr)
     VALUES (ltrim(rtrim(@leftover)), ltrim(rtrim(@leftover)))
  RETURN
END


Implementation:

CREATE PROCEDURE get_company_names_iter @customers nvarchar(2000) AS
      SELECT C.CustomerID, C.CompanyName
      FROM   Northwind..Customers C
      JOIN   iter_charlist_to_tbl(@customers, DEFAULT) s
        ON   C.CustomerID = s.nstr
   go
   EXEC get_company_names_iter 'ALFKI, BONAP, CACTU, FRANK'

strip out all non letter/number characters from a series of


I need to strip out all non letter/number characters from a series of
strings in a query. Is there a better way to do this than a bunch of
replace functions?

/*********************************
Removes any characters from
@myString that do not meet the
provided criteria.
*********************************/
CREATE FUNCTION dbo.GetCharacters(@myString varchar(500), @validChars varchar(100))
RETURNS varchar(500) AS
BEGIN

 While @myString like '%[^' + @validChars + ']%'
  Select @myString = replace(@myString,substring(@myString,patindex('%[^' + @validChars + ']%',@myString),1),'')

 Return @myString
END
Go

Declare @testStr varchar(1000),
 @i int

Set @i = 1
while @i < 255
 Select
  @TestStr = isnull(@TestStr,'') + isnull(char(@i),''),
  @i = @i + 1

Select @TestStr
Select dbo.GetCharacters(@TestStr,'a-z')
Select dbo.GetCharacters(@TestStr,'0-9')
Select dbo.GetCharacters(@TestStr,'0-9a-z')
Select dbo.GetCharacters(@TestStr,'02468bferlki')

Tuesday, April 1, 2008

1900-01-01 00:00:00.000 bug

bug: 1900-01-01 00:00:00.000 entry in SQL cause: when you enter blank string into a datetime type field the default value is 1900-01-01 00:00:00.000 fix: don't insert empty/blank string into field that is a datetime type.
LINQ: - LinQto Object : use of standard query operator (SQO) for pulling data from any object that can be implemented by interface IEnumerable. This query can be use for data in memory. - LinQ to ADO.NET: LinQ to SQL , LinQ to dataset, LinQ to Entities - LinQ to XML hello word in LinQ: class Program { static void Main(string[] args) { string[]helloWord={"hello","this","is", "LINQ","by","Philip","H" }; var results = from word in helloWord where(word[0]>'g' || (word[0]>'K'&& word[0]<'M')) select word+' '; foreach(var wordItem in results) Console.Write(wordItem); } }