I was working on a Functionality and came i cross duplicates in a Database table Field, so i thought that i will just put this string in a arralist and remove the Duplicates from there , but i thought how Arraylist are slow i thought mybe it will be good to do it here in sql, while googling i came across a very interesting post by Pinal Dave and the post originally written by Ashish Jain . you can Find it here http://blog.sqlauthority.com/2009/01/15/sql-server-remove-duplicate-entry-from-comma-delimited-string-udf/
Here is How it was done,
Create a UDF(User Derfined Function)
alter FUNCTION dbo.DistinctList
(
@List VARCHAR(MAX),
@Delim CHAR
)
RETURNS
VARCHAR(MAX)
AS
BEGIN
DECLARE @ParsedList TABLE
(
Item VARCHAR(MAX)
)
DECLARE @list1 VARCHAR(MAX), @Pos INT, @rList VARCHAR(MAX)
SET @list = LTRIM(RTRIM(@list)) + @Delim
SET @pos = CHARINDEX(@delim, @list, 1)
WHILE @pos > 0
BEGIN
SET @list1 = LTRIM(RTRIM(LEFT(@list, @pos - 1)))
IF @list1 <> ''
INSERT INTO @ParsedList VALUES (CAST(@list1 AS VARCHAR(MAX)))
SET @list = SUBSTRING(@list, @pos+1, LEN(@list))
SET @pos = CHARINDEX(@delim, @list, 1)
END
SELECT @rlist = COALESCE(@rlist+',','') + item
FROM (SELECT DISTINCT Item FROM @ParsedList) t
RETURN @rlist
END
And Run your Fuction like this
SELECT dbo.DistinctList(MY_FIELD,' ') DistinctList FROM MYTABLE
This Function takes two parameters the first one is the duplicated string, in this case i have used my field in mytable. e.g if you have
"12345612345" and run this on your field ,you will end up with
"123456"
Thanks
Vuyiswa Maseko
Wednesday, May 6, 2009
Wednesday, April 29, 2009
How to Show a Mesage Box in ASP.NET
A lot of Developer from windows Platform who are new to Web Development , tries to mimic what they were doing in Windows Development on the Web. Well it would be nice if Microsoft can add this feuture in ASp.net. Message boxes are the way a Developer interect with his or her users. In Windows Application its simple because you just need to call the Function
MessageBox.Show("Your Message here...");
This can still be used in the Web but , your message box will show at the taskbar and this will not be your intentions. To over come this in Asp.net you have to create a Function like this
public void CreateMessageAlert(System.Web.UI.Page aspxPage, string strMessage, string strKey)
{
string strScript = "";
if (!ClientScript.IsStartupScriptRegistered(strKey))
{
ClientScript.RegisterStartupScript(typeof(Page), strKey, strScript);
}
}
and you can call it like this
string strMessage = "You Message here...";
CreateMessageAlert(this.Page, strMessage, "strKey1");
That is Simple.
Vuyiswa Maseko
MessageBox.Show("Your Message here...");
This can still be used in the Web but , your message box will show at the taskbar and this will not be your intentions. To over come this in Asp.net you have to create a Function like this
public void CreateMessageAlert(System.Web.UI.Page aspxPage, string strMessage, string strKey)
{
string strScript = "";
if (!ClientScript.IsStartupScriptRegistered(strKey))
{
ClientScript.RegisterStartupScript(typeof(Page), strKey, strScript);
}
}
and you can call it like this
string strMessage = "You Message here...";
CreateMessageAlert(this.Page, strMessage, "strKey1");
That is Simple.
Vuyiswa Maseko
Tuesday, April 28, 2009
The State Information is Invalid for this Page and might be Corrupted
Some other Errors are not code related and but they can be solved through the code. Am uploading the Xml file to ym DB and am using Infragistics Controls to do this , it will work for very small files but it will give you a problem with a larger Files. Here is the cause
Problem:
This comes, because from version 2.2.2, we made the RadUploadHttpModule parse the files when used with the Cassini web server. I believe you have encountered a similar problem - the request data is not read properly by the RadUploadHttpModule and corrupt ViewState data is passed to the page. and you finnaly get the error
The case-sensitive value that the TemplateSourceDirectory property of a page returns is used to create and to validate the ViewState property for that page. The value of this property for a page depends on the case-sensitive URL that the first user for that page requested. This value is reused for the remaining requests for that page until that page is recompiled. When the page is recompiled, the TemplateSourceDirectory property is re-initialized. If the new value (which is case-sensitive) differs from the previous value, the ViewState validation from the existing clients fails.
The State Information is Invalid for this Page and might be Corrupted
Resolutions:
Problem:
This comes, because from version 2.2.2, we made the RadUploadHttpModule parse the files when used with the Cassini web server. I believe you have encountered a similar problem - the request data is not read properly by the RadUploadHttpModule and corrupt ViewState data is passed to the page. and you finnaly get the error
The case-sensitive value that the TemplateSourceDirectory property of a page returns is used to create and to validate the ViewState property for that page. The value of this property for a page depends on the case-sensitive URL that the first user for that page requested. This value is reused for the remaining requests for that page until that page is recompiled. When the page is recompiled, the TemplateSourceDirectory property is re-initialized. If the new value (which is case-sensitive) differs from the previous value, the ViewState validation from the existing clients fails.
The State Information is Invalid for this Page and might be Corrupted
Resolutions:
- Someone else reported the same error and seemed to have found a workaround by causing his upload button PostbackUrl to go to the same page like this
btnAddFile.PostBackUrl = "~/NewsAddFiles.aspx?NewsId=" + hiddenNewsId.Value;
2. Download a hotFix http://support.microsoft.com/default.aspx?scid=kb;ko;323744
http://support.microsoft.com/ph/1173#tab0
3: Save the radion button selection and tree control node selection in session variables instead of view state, because the life scope of the view state is only within the page. When user navigates away to a different page, the view state of the previous page is destroyed.
Hope this This Helps
Vuyiswa Maseko
Tuesday, March 24, 2009
Cannot Find keycodev2.dll or invalid keycode
Have you ever come across this problem, when you have crystal report setup file. Which includes all the merge modules and license key for crystal reports. But still you are getting this error while deploying your application on the server.
Solution:
http://support.businessobjects.com/fix/merge_modules.asp
http://support.businessobjects.com/communityCS/FilesAndUpdates/cr9netredist.zip.asp
http://support.businessobjects.com/communityCS/TechnicalPapers/crnet_keycodev2.pdf.asp
Thank you
Vuyiswa Maseko
Solution:
- Deploy the application including the mergemodules:
Crystal_Database_Access2003.msm (necessary if you use ado)
Crystal_Database_Access2003_enu.ms m (necessary if you use ado)
Crystal_Managed2003.msm
Crystal_regwiz2003.msm (don't forget to set license key in properties)
VC_User_CRT71_RTL_X86_---.msm
VC_User_MFC71_RTL_X86_---.msm
http://support.businessobj
http://support.businessobj
http://support.businessobj
Thank you
Vuyiswa Maseko
Cannot Create Windows Folder Named Con
Status:
It is true that you cannot create a folder with the Following names
Microsoft MS-DOS reserves certain names for system device drivers. If you try to name a file using one of these names, you will receive the following error message:
Write Fault Error Writing Device
Abort, Retry, Ignore, Fail?
The solution is to change the file name.
Below is a list of default device driver names.
To identify system device driver names, use one of the following two commands:
Thank you
Vuyiswa Maseko
It is true that you cannot create a folder with the Following names
- PRN
- AUX
- NUL
- LPT1
- COM1
- Potential drive letter - A: to Z:
- A number of others
Microsoft MS-DOS reserves certain names for system device drivers. If you try to name a file using one of these names, you will receive the following error message:
Write Fault Error Writing Device
Abort, Retry, Ignore, Fail?
The solution is to change the file name.
Below is a list of default device driver names.
Name Function
---- --------
CON Keyboard and display
PRN System list device, usually a parallel port
AUX Auxiliary device, usually a serial port
CLOCK$ System real-time clock
NUL Bit-bucket device
A:-Z: Drive letters
COM1 First serial communications port
LPT1 First parallel printer port
LPT2 Second parallel printer port
LPT3 Third parallel printer port
COM2 Second serial communications port
COM3 Third serial communications port
COM4 Fourth serial communications port
- mem /d more
- debug d 0070:0000
APPLIES TO
- Microsoft MS-DOS 2.11 Standard Edition
- Microsoft MS-DOS 3.1
- Microsoft MS-DOS 3.2 Standard Edition
- Microsoft MS-DOS 3.21 Standard Edition
- Microsoft MS-DOS 3.3 Standard Edition
- Microsoft MS-DOS 3.3a
- Microsoft MS-DOS 4.0 Standard Edition
- Microsoft MS-DOS 4.01 Standard Edition
- Microsoft MS-DOS 5.0 Standard Edition
- Microsoft MS-DOS 5.0a
- Microsoft MS-DOS 6.0 Standard Edition
- Microsoft MS-DOS 6.2 Standard Edition
- Microsoft MS-DOS 6.21 Standard Edition
- Microsoft MS-DOS 6.22 Standard Edition
Thank you
Vuyiswa Maseko
Tuesday, March 17, 2009
Could not load file or assembly 'App_Code' or one of its dependencies. There is not enough space on the disk. (Exception from HRESULT: 0x80070070)new
हवे यू एवर काम आक्रोस अन एर्रोर लिखे थिस
Could not load file or assembly 'App_Code' or one of its dependencies। There is not enough space on the disk. (Exception from HRESULT: 0x80070070)
दो नोट पनिक, थिस इस नोट अ प्रॉब्लम इन यौर ऍप्लिकेशन और यौर कोड, बुत इट्स अ प्रॉब्लम ओं यौर सर्वर।। तेरे अरे प्लेंटी ऑफ़ रेसोलुशन तो थिस प्रॉब्लम ,
1) रन थे डिस्क क्लेअनुप तो रेमोवे उनुसेद और टेम्प फिल्स एंड रिस्टार्ट यौर सर्वर अनडी विल सोल्वे यौर प्रॉब्लम
२)That's pretty clearly a disk space error। While your account may have plenty of disk space available, the error might refer to the operating system partition on the machine - since the error occurs when assemblies are being loaded into memory which likely will occur on the OS disk. Your Web space is probably on a different partition than the OS, and there is probably plenty of space there.
ठनक you
Could not load file or assembly 'App_Code' or one of its dependencies। There is not enough space on the disk. (Exception from HRESULT: 0x80070070)
दो नोट पनिक, थिस इस नोट अ प्रॉब्लम इन यौर ऍप्लिकेशन और यौर कोड, बुत इट्स अ प्रॉब्लम ओं यौर सर्वर।। तेरे अरे प्लेंटी ऑफ़ रेसोलुशन तो थिस प्रॉब्लम ,
1) रन थे डिस्क क्लेअनुप तो रेमोवे उनुसेद और टेम्प फिल्स एंड रिस्टार्ट यौर सर्वर अनडी विल सोल्वे यौर प्रॉब्लम
२)That's pretty clearly a disk space error। While your account may have plenty of disk space available, the error might refer to the operating system partition on the machine - since the error occurs when assemblies are being loaded into memory which likely will occur on the OS disk. Your Web space is probably on a different partition than the OS, and there is probably plenty of space there.
ठनक you
Monday, March 16, 2009
How to Get the Selected Item in a ListBox Control(ASP.NET 2.0,3.5 C#)
Many People who start developing on ASP.NET C#, they usually find it difficult to bind and get the selected item in the listbox and Dropdownlist control. This is how simple it is
String myselecteditem = listBox1.SelectedItems;
And you can do the same thing with a Dropdownlist
String mydropdownlist = dropdownlist1.SelectedItems;
Now all this will return what a user see on the List box, if it’s a list of numbers like {1,2,3,4,5} then the value that will be contained in there is that.
Thanks
String myselecteditem = listBox1.SelectedItems;
And you can do the same thing with a Dropdownlist
String mydropdownlist = dropdownlist1.SelectedItems;
Now all this will return what a user see on the List box, if it’s a list of numbers like {1,2,3,4,5} then the value that will be contained in there is that.
Thanks
Subscribe to:
Posts (Atom)