Search
Monday, April 21, 2008
Saturday, April 19, 2008
Thursday, April 17, 2008
Data grid Paging for C#
Data grid Paging for C# example:
http://www.codeproject.com/KB/database/DataGridPaging.aspx
Tuesday, April 15, 2008
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.aspxntext 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 languagesHow 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:
	 for tab,
  for space,
  for non-breaking space.
< for < > 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
‘ ‘ left single quote
’ ’ right single quote
‚ ‚ single low-9 quote
“ “ left double quote
” ” right double quote
„ „ double low-9 quote
† † dagger
‡ ‡ double dagger
‰ ‰ per mill sign
‹ ‹ single left-pointing angle quote
› › single right-pointing angle quote
♠ ♠ black spade suit
♣ ♣ black club suit
♥ ♥ black heart suit
← ← leftward arrow
↑ ↑ upward arrow
→ → rightward arrow
↓ ↓ downward arrow
™ ™ trademark sign
Name Code Number Code Glyph Description
	 horizontal tab
line feed
  space
! ! exclamation mark
" " " double quotation mark
# # number sign
$ $ dollar sign
% % percent sign
& & & ampersand
' ' apostrophe
( ( left parenthesis
) ) right parenthesis
* * asterisk
+ + plus sign
, , comma
- - hyphen
. . period
Name Code Number Code Glyph Description
⁄ / / slash
0-
9 digits 0-9
: : colon
; ; semicolon
< < < less-than sign
= = equals sign
> > > greater-than sign
? ? question mark
@ @ at sign
A-
Z uppercase letters A-Z
[ [ left square bracket
\ \ backslash
] ] right square bracket
^ ^ caret
_ _ horizontal bar (underscore)
` ` grave accent
a-
z lowercase letters a-z
{ { left curly brace
| | vertical bar
Name Code Number Code Glyph Description
} } right curly brace
~ ~ tilde
– – – en dash
— — — em dash
  nonbreaking space
¡ ¡ ¡ inverted exclamation
¢ ¢ ¢ cent sign
£ £ £ pound sterling
¤ ¤ ¤ general currency sign
¥ ¥ ¥ yen sign
¦ or &brkbar; ¦ ¦ broken vertical bar
§ § § section sign
¨ or ¨ ¨ ¨ umlaut
© © © copyright
ª ª ª feminine ordinal
« « « left angle quote
¬ ¬ ¬ not sign
­ ­ soft hyphen
® ® ® registered trademark
¯ or &hibar; ¯ ¯ macron accent
Name Code Number Code Glyph Description
° ° ° degree sign
± ± ± plus or minus
² ² ² superscript two
³ ³ ³ superscript three
´ ´ ´ acute accent
µ µ µ micro sign
¶ ¶ ¶ paragraph sign
· · · middle dot
¸ ¸ ¸ cedilla
¹ ¹ ¹ superscript one
º º º masculine ordinal
» » » right angle quote
¼ ¼ ¼ one-fourth
½ ½ ½ one-half
¾ ¾ ¾ three-fourths
¿ ¿ ¿ inverted question mark
À À À uppercase A, grave accent
Á Á Á uppercase A, acute accent
   uppercase A, circumflex accent
Name Code Number Code Glyph Description
à à à uppercase A, tilde
Ä Ä Ä uppercase A, umlaut
Å Å Å uppercase A, ring
Æ Æ Æ uppercase AE
Ç Ç Ç uppercase C, cedilla
È È È uppercase E, grave accent
É É É uppercase E, acute accent
Ê Ê Ê uppercase E, circumflex accent
Ë Ë Ë uppercase E, umlaut
Ì Ì Ì uppercase I, grave accent
Í Í Í uppercase I, acute accent
Î Î Î uppercase I, circumflex accent
Ï Ï Ï uppercase I, umlaut
Ð Ð Ð uppercase Eth, Icelandic
Ñ Ñ Ñ uppercase N, tilde
Ò Ò Ò uppercase O, grave accent
Ó Ó Ó uppercase O, acute accent
Ô Ô Ô uppercase O, circumflex accent
Õ Õ Õ uppercase O, tilde
Name Code Number Code Glyph Description
Ö Ö Ö uppercase O, umlaut
× × × multiplication sign
Ø Ø Ø uppercase O, slash
Ù Ù Ù uppercase U, grave accent
Ú Ú Ú uppercase U, acute accent
Û Û Û uppercase U, circumflex accent
Ü Ü Ü uppercase U, umlaut
Ý Ý Ý uppercase Y, acute accent
Þ Þ Þ uppercase THORN, Icelandic
ß ß ß lowercase sharps, German
à à à lowercase a, grave accent
á á á lowercase a, acute accent
â â â lowercase a, circumflex accent
ã ã ã lowercase a, tilde
ä ä ä lowercase a, umlaut
å å å lowercase a, ring
æ æ æ lowercase ae
ç ç ç lowercase c, cedilla
è è è lowercase e, grave accent
Name Code Number Code Glyph Description
é é é lowercase e, acute accent
ê ê ê lowercase e, circumflex accent
ë ë ë lowercase e, umlaut
ì ì ì lowercase i, grave accent
í í í lowercase i, acute accent
î î î lowercase i, circumflex accent
ï ï ï lowercase i, umlaut
ð ð ð lowercase eth, Icelandic
ñ ñ ñ lowercase n, tilde
ò ò ò lowercase o, grave accent
ó ó ó lowercase o, acute accent
ô ô ô lowercase o, circumflex accent
õ õ õ lowercase o, tilde
ö ö ö lowercase o, umlaut
÷ ÷ ÷ division sign
ø ø ø lowercase o, slash
ù ù ù lowercase u, grave accent
ú ú ú lowercase u, acute accent
û û û lowercase u, circumflex accent
Name Code Number Code Glyph Description
ü ü ü lowercase u, umlaut
ý ý ý lowercase y, acute accent
þ þ þ lowercase thorn, Icelandic
ÿ ÿ ÿ 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);
}
}
Subscribe to:
Posts (Atom)
