tag:blogger.com,1999:blog-296970052024-03-08T10:03:58.450-08:00.NETHi,
This is Mr Surendra Sambana.
Welcome to the world of computation.
This site address typical requirements in .NET Web Apllications.Enjoy reading the articles and Happy Programming.Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.comBlogger11125tag:blogger.com,1999:blog-29697005.post-71644538690074261112007-10-08T03:40:00.000-07:002008-12-11T01:00:45.270-08:00Providing Google like "Processing........" statusIf you wanted to provide status bar for your pages as in Google.<br />you cab use below code to achieve the same.<br />Scnario:<br />1.Currently you are on Page1(start.aspx).Your post back leads you to Page2(End.aspx)<br />2.End.aspx is taking a while to load, so you want to show some status as in shown in Gmail.<br /><br />Below screen shot will explain the same in detail.<br /><span style="font-weight:bold;">Start.aspx</span><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8RBYHOcFm8g/RwoPTK_g3MI/AAAAAAAAAMk/Ro82JLKGbyc/s1600-h/Start_aspx.GIF"><img style="cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_8RBYHOcFm8g/RwoPTK_g3MI/AAAAAAAAAMk/Ro82JLKGbyc/s320/Start_aspx.GIF" border="0" alt=""id="BLOGGER_PHOTO_ID_5118920748502670530" /></a><br /><br />In Code behind file of Start.aspx button click event handler looks like this.<br><br /> <span style="font-weight:bold;">public void BtnClick(object sender, System.EventArgs e)<br /> {<br /> // Write your code here<br /> string url = "Inter.aspx?target=End.aspx";<br /> HttpContext.Current.Response.Redirect(url);<br /> }</span><br /><br /><br /><span style="font-weight:bold;">Inter.aspx</span> just consist simple mesage as below.<br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://1.bp.blogspot.com/_8RBYHOcFm8g/Rw4FFK_g3SI/AAAAAAAAANQ/Cu-dw-_-Rl4/s1600-h/inter_aspx.bmp"><img style="cursor:pointer; cursor:hand;" src="http://1.bp.blogspot.com/_8RBYHOcFm8g/Rw4FFK_g3SI/AAAAAAAAANQ/Cu-dw-_-Rl4/s320/inter_aspx.bmp" border="0" alt=""id="BLOGGER_PHOTO_ID_5120035412775066914" /></a><br /><br /><span style="font-weight:bold;">Inter.aspx.cs</span> looks like below.<br />public class Inter : System.Web.UI.Page<br /> {<br /> protected HtmlGenericControl bd;<br /> private void Page_Load(object sender, System.EventArgs e)<br /> {<br /> // Put user code to initialize the page here<br /> HtmlGenericControl body = (HtmlGenericControl)Page.FindControl("bd");<br /> if (body != null)<br /> {<br /> body.Attributes["onload"] = GetAutoRedirectScript();<br /> }<br /><br /> }<br /><br /> public string GetAutoRedirectScript()<br /> {<br /> return String.Format("location.href='{0}';", "End.aspx");<br /> <br /> }<br /> }Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com6tag:blogger.com,1999:blog-29697005.post-12193778064668454482007-08-31T02:23:00.000-07:002007-08-31T04:57:19.069-07:00Firing/Invoking Multiple Javascript fuctions on body onloadOften we land up in a scenario, where we require to invoke more than 2 javascript functions on Page Load.<br />We can call one function straight away by calling a function on 'onload' event of body tag. 2nd function u can invoke by overriding Render event of page life cycle. You can over-ride 'Render' event as below. <br />protected override void Render (HtmlTextWriter writer)<br />{<br /> base.Render (writer);<br /> writer.Write("<script language=javascript> f1()</script>");<br />}<br />Note:<br />Developers often try to achieve the same functionality by calling javascript function as below.<br /> Response.Write("<script language=javascript>f1()</script>");<br />It results in an error, because "Response.Write" tries to call the function even before page load happens, hence it can't find/locate required javascript fuction in page, which results in an error.Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com1tag:blogger.com,1999:blog-29697005.post-17580358474928969522007-07-13T01:51:00.001-07:002007-08-17T00:57:04.466-07:00Creating JavaScript Member functionsSyntax for creating your member functions in JavaScript<br /><br />String.prototype.FunctionName = function() <br />{<br />// write your logic;<br />return 'return value';<br />}<br /><br />You can convvert above mentioned <a href="http://ssurendra.blogspot.com/2007/07/javascript-convert-char-to-ascii.html">ToAscii</a> fuction as member function, Thats left for the readers for practice.<br /><br />Here are some frequently used functions.<br />Examples:<br /> 1.Trim<br /> String.prototype.Trim = function() <br /> {<br /> return this.replace(/^\s+|\s+$/g,"");<br /> }<br /> 2.Ltrim<br /> String.prototype.Ltrim = function() <br /> {<br /> return this.replace(/^\s+/,"");<br /> }<br /> 3.Rtrim<br /> String.prototype.rtrim = function() <br /> {<br /> return this.replace(/\s+$/,"");<br /> }Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com0tag:blogger.com,1999:blog-29697005.post-1160414163022921772006-10-09T09:58:00.000-07:002006-10-09T10:16:03.056-07:00Why do Oracle commits when we issue a DDL statement?In DDL operation, DDL locks wiil be taken place automatically against the respective object. So one needs to remove the locks as soon as the statement got executed, it can be achieved by commiting the transaction. The next Question is what if the transaction fails. the answer is oracle simply rollback.The next complication is if it rollback, user looses their transactions that happend just before the DDL statement.Thats why Oracle executes a commit statement just before the DDL also. Thats the reason why the end user transactions will be committed irrespective of the success of DDL. A DDL statement actually execute as below<br /> commit;<br /> DDL<br /> commit;<br /> Exception<br /> rollbackSurendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com0tag:blogger.com,1999:blog-29697005.post-1157528067714637702006-09-06T00:32:00.000-07:002006-10-09T09:56:59.700-07:00Do all value types reside is stack?The simple answer is NO.<br />In any class we have variables at global level and local (specific to a method/function) level..<br />At the time of execution the method code will be loaded into stack andhence all the value types refered in the method will be reside in stack. If the values types are declared at class level those variables will be stored in heap.Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com1tag:blogger.com,1999:blog-29697005.post-1154955982410795862006-08-07T05:23:00.000-07:002006-09-06T00:31:33.506-07:00A brief description about Oracle architectureFirst I'd like to discuss about common terminology that helps us in understanding the architecture.<br />In Oracle we can describe storage mechanism in 2ways logical storage structures and physical storage structures storage consist of DATA FILES which are nothing but the (OS)files on hard disc.<br />Logical Storage:<br />'<span style="font-weight: bold;">DataBlock</span>' is the smellest unit of storage for I/O operations in oracle DB. Whose size is (obviously) greater than OS block and its multiple of OS block. its size can be configured and by default its 2048. A datablock consist of contiguous OS blocks.<br /><span style="font-weight: bold;"><br />'Extents</span>' The next level of logical space unit is Extent. It consists of contiguous DataBlocks. Database allocates space in terms of extents when ever its required.<br /><span style="font-weight: bold;"><br />'Segments'</span> Is the next level of logical storage unit. A segment is a set of extents that are allocate d for a specific type of datastructure (that means data and indexes will get stored in different segments).<br /><br /><span style="font-weight: bold;">'TableSpace' </span>is the top level unit of logical storage structure in Oracle database.The data of a database is logically stored in tablespaces and physically stored in datafiles that are associated to a tablespace. A database is comprised of 1 or more logical storage units called tablespace. By default every DB creates a tablespace called 'System' when the database is created.Each tablespace is consist of 1 or more physical(OS) files called datafiles.<br /><br />At the time of table creation one can mention its tablespace. A database object (table, view etc) can span a datafile but can't a tablespace.<br /><br /><span style="font-weight: bold;">Anatomy of DB Block</span>:<br />Irrespective of its content(data, index or clustured data) each database block consist of below parts.<br />1.Common and variable header 2.Table directory 3.Row directory 4. Free space 5. Row data<br /><br /><span style="font-weight: bold;">Header</span> contains the block information like address of the block, type of segment(data, index or rollback). Please note part of the header size is fixed but total header size is variable.<br /><br /><span style="font-weight: bold;">Table directory</span> the name it self explains, it contains table information which having rows in the block.(this shows a block can hold data related to more than 1 table). But please not that a datablock can hold rows of different tables only if they are clustered else a data block can't hold data related to 2 different tables.<br />Note: If a data block contains data for cluster(having 2 or more tables) then datablock free space is managed by the cluster storage clause not by individual table pct*** factors.<br /><br /><span style="font-weight: bold;">Row directory</span> this part of the block contains the information(address of each row) about the rows in the block. Please note that space allocated in the row directory can't be reclaimed when the row is deleted (place where we need to think about High Water Mark)<br /><br /><span style="font-weight: bold;">RowData</span> This portion contains actual data (table data or index).<br /><br /><span style="font-weight: bold;">Free Space</span> is used to accommodate new rows(insert) or updates to existing rows. Based on PCTFREE factor row insertion will be decided(i.e a new row will occupy the same block or other block).<br /><br /><span style="font-weight: bold;">PCTFREE</span> and <span style="font-weight: bold;">PCTUSED</span> are the 2 space management parameters that allow the user to control the use of free space in a block.<br /><br />PCTFREE decides the %of the block to be kept free for future updates to rows. 'pctfree 10' says that 10% of every block of the segment that used for the table kept free for future updates on the table.And the other important point is as and when a blocks pctfree reaches specified limit it'll get out of the free list.<br />Data will be filled in the block by sparing the % specified in pctfree. Now we deleted some rows in the block.Question arises as "Now is the block is ready for new insertions?"(as it has some free space apart from pctfree). This will be answered by PCTUSE. The block can't be considered for new insertions until and unless its usage falls below the PCTUSE. viz if you say PCTUSE 50, and the block is filled fully(sparing space for pctfree). The block will be considered for insertions if and only if its usage falls below 50%.<br /><br /><span style="font-weight: bold;">How Oracle allocates Extents?<br /></span>A segment in a database is created with at least one extent. This is called segment's initial extent. As and when this initial extent is full and the database object need more space to accommodate its data, Oracle allocates an extent(incremental) to the segment. But how?..<br />Oracle searches for free contiguous block of size(= size of required extent + 1(if its > 5 blocks)) in the same tablespace of the segment. Lets say if extent requires 10 blocks. It searches for 10+1 contiguous block and if it finds the same then it allocates that space as an extent to the segment. If the required extent size <= 5 then it just searches for required blocks (no +1). Note: Infact this additional block is added to address internal fragmentation. We can just remeber this as below. If(No of blocks required > 5)<br />No of searched blocks = No of blocks required + 1<br />else<br />No of searched blocks = No of blocks required<br />case 1.<br />If oracle didn't find the exact match but finds a larger no of contiguous blocks.It allocates blocks to the extent as below.<br />i. If 'No of contiguous blocks available' > 'No of searched blocks' + 5<br />Then it just allocates 'No of searched blocks' from available to the extent & hence to segment.<br />ii. If 'No of contiguous blocks available' <= 'No of searched blocks' + 5 Then it allocates all the block to the extent and then to segment. case 2. If Oracle does't find a larger set of contiguous data blocks, It then coalesces free space in the tablespace so that it results in the formation of larger contiguous data blocks. Once again oracle start searching as mentioned in case 1. if it fails to find then Oracle returns an error. Note: Infact SMON(System Monitor back ground Process) will periodically coalesces the free space to create larger chunks of contiguous blocks. <span style="font-weight: bold;"><br /><br /></span><span style="font-weight: bold;">Some thing about SGA</span>: System Global Area<br /><br />*Please note that above information is just my understanding, by reading various article on net with some of my own assumptions. Pease let me know if I am wrong anywhere.Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com44tag:blogger.com,1999:blog-29697005.post-1153995307527858992006-07-27T03:14:00.000-07:002006-09-19T00:29:58.566-07:00Is HashCode Unique?I found in many sites and artilce saying Hashcode is unique. But thats not true always.<br />just consider this example. As u know HashCode is int32, that means at a given point of time u can have max 2^32 different values. At that point of time u can have more than 2^32 different objects. That means hashcode must be duplicated.<br /><br />There is another claim saying at least for string objects hascode is unique, that is also not true, the reason is. As we have 26 alphabets total no of differe string u can have is 26!(26 factorial) (I am just considering 26 char length single word only), which is bigger number than 2^32. That means two different string can have same hashcode is it not!.<br />Based on the above discussion we can say Hashcode is not unique.<br /><br />*Please not that this is just my understanding, Correct me if i am wrong.Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com5tag:blogger.com,1999:blog-29697005.post-1153288041276183682006-07-18T22:46:00.000-07:002006-07-20T00:36:14.496-07:00Sending a DataTable as parameter to Stored Procedure(SQL Sever 2000)<p>Quite often i faced a cese where i need to send a DataTable or array to the procedure as parameter. As we all know SQL 2000 takes paramteres as varchar,char,int,text etc. But there are occation where we required to send Full DataTable to DB. In those case we usually pump data to DB, record by record. Here is a work around for that. Lets Assume we have to send a table(see below) as parameter to Stored Procedure.</p><table style="width: 225px; height: 80px;" border="1" cellpadding="0" cellspacing="0"><tbody><tr><td><b>Person</b></td><td> <b>Discovery</b></td></tr><tr><td>Einstein</td><td>Theory of relativity</td></tr><tr><td>Newton</td><td>Laws of Cooling</td></tr><tr><td>Niels Bhore</td><td>Atomic Model</td></tr></tbody></table>Now convert the above table as string using a (C#)class.The resultant string looks like this<br />"<br /> '''Person'',''Discovery'',~''Einstein'',''Theory of relativity'',~''Newton'',''Laws of Cooling'',~',~''Niels Bhore'',''Atomic Model'',~'<br />"<br />We can send this string to SP as a parameter directly. So the SP that take this string as input parameter looks as below.<br />Create Procedure usp_update_peopleTable<br />@inputTable varchar(8000)<br />----<br />as<br />begin<br /> ---<br />end<br /><br />But there is constraint as varchar can just hold(8000 chars) so we have to declare a variable type which can hold more data. So we have to use Text/Image instead of Varchar. so the SP looks as below.<br />Create Procedure usp_update_peopleTable<br />@inputTable text<br />----<br />as<br />begin<br /> ---<br />end<br />I just want to repat the the stuff what we done still now.In App server we have a table that we need to send to DB. we converted the table as a string, now we sent the string to SP.<br />Now we have to chage input string to SP as Table again so that we can manipulate that as we require.So next task is to covert the String to Table in DB. Below SP address the same task. This SP takes 2 input parameters and results a Table, 1st param the strig that u have to convert to a table, 2nd param number of columns of the table. Teh SP is as below.<br /><br />alter procedure usp_get_table_from_text<br />@inputtxt text,<br />@no_cols int<br />as<br />begin<br /> declare @charposition int,@row varchar(8000),@strsql varchar(8000)<br /> create table #data_holder<br /> (<br /> rowid int,<br /> textvalue text<br /> )<br /> <br /> set @strsql = 'create table output_table ('<br /> while(@no_cols != 0)<br /> begin<br /> set @strsql = @strsql+ ' col' + cast(@no_cols as varchar) + ' varchar(2000),'<br /> set @no_cols = @no_cols -1<br /> end<br /> set @strsql = substring(@strsql,1,len(@strsql)-1)+ ')'<br /> <br /> exec(@strsql)<br /> <br /> set @charposition = charindex('~',@inputtxt)<br /> insert into #data_holder values(1,@inputtxt)<br /> <br /> while(@charposition > 1)<br /> begin<br /> select @row = substring(textvalue,1,@charposition-1) from #data_holder where rowid = 1<br /> <br /> set @strsql = 'insert into output_table values(' + substring(@row,1,len(@row)-1) + ')'<br /> exec(@strsql)<br /> <br /> update #data_holder set textvalue= substring(textvalue,@charposition+1,datalength(textvalue))<br /> <br /> <br /> select @charposition = charindex('~',textvalue) from #data_holder where rowid = 1<br /><br /> end<br /> drop table #data_holder<br /> select * from output_table<br /> drop table output_table<br />end<br /><br />Just for understanding create SP in u r DB and execute below Query. SO that you can get some understanding what its doing. <br /><br />exec usp_update_peopleTable '''Person'',''Discovery'',~''Einstein'',''Theory of relativity'',~''Newton'',''Laws of Cooling'',~',~''Niels Bhore'',''Atomic Model'',~',2<br /><br />I am so sorry to say that there were no cooments in above SP. i'll add comments as and when i get soem time.<br />Conclusion:<br /> Steps to use the stuff<br /> Objective: when vere u need to send a Table directly to DB folow these steps.<br /> 1. Covert the Table to String in App Server.<br /> 2. send teh converted string to your SP that consumes the Table.<br /> 3. In your SP use sp 'usp_get_table_from_text' to convert the string to table<br /> 4. Manipulate the table as you want.<br />Hope this might help you all.Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com14tag:blogger.com,1999:blog-29697005.post-1153285049111159522006-07-18T21:57:00.000-07:002006-07-19T00:00:36.276-07:00External Tool for VS(Visual Studio)2003 to change the file attributesHi All: This Article describes adding your own tool to VS 2003<br />Problem:<br />If you intigrate VS 2003 with VSS, as and when u get the latest version the respective file(s) become "Read Only". So when ever u want to edit the file, u have to check out the file, else if u want to make changes locally, u have to dig till that file using Win Explorer and have to uncheck the Read only attribute. Imagine if the project is having many subdirectories, then its bit difficult to change the read only attribute of the file(s) by navigating thru explorer.<br />Solution:<br />If there is any way that address the above task, directly from VS IDE that will difinitely help us. Here is a way out. I just added a external tool, that appears under Tools menu.<br /><br />U have to write a class that acceppts a file_path as argument. And u have to change teh file attributes thru code.Here i wrote a class that exactly do the same stuff.<br /><br />using System;<br />using System.IO;<br />using System.Text;<br /><br />namespace Surendra.ExternalTools.SetFileAttributes<br />{<br />public class ChangeFileAccessAttributes<br />{<br /> public static void Main(string[] args)<br /> {<br /> string strFilePath = args[0].ToString();<br /><br /> File.SetAttributes(strFilePath, FileAttributes.Archive);<br /> }<br />}<br />}<br /><br />Creation of EXE:<br />Now u have to create an EXE for the above class. u can achieve teh same through CMD as below.<br /><br /><p>"C:\Surendra\PersonalProjects\ExternalTools>csc ChangeFileAccessAttributes.cs"</p>Integration of the tool to VS IDE:<br /><p>step1: Open MS VS. Click on Tools Main Menu, then click on External tool..<br />A pop up will open for u.<br /><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7492/3170/1600/ExpernalToolsPopUp.jpg"><img style="margin: 0px auto 10px; display: block; text-align: center; cursor: pointer;" src="http://photos1.blogger.com/blogger/7492/3170/320/ExpernalToolsPopUp.jpg" alt="" border="0" /></a><br /><br />Step 2:Click on Add button.<br />just fill out the text boxes as<br />Title: Remove Read Only<br />Command: Path of the ChangeFileAccessAttributes.exe<br />Arguements: "$(ItemPath)"<br />And finally press OK button..<br />Thats it.. your new tool will get ready and that appears under Tools menu as shown below.<br /></p><br /><a onblur="try {parent.deselectBloggerImageGracefully();} catch(e) {}" href="http://photos1.blogger.com/blogger/7492/3170/1600/ResultTools.jpg"><img style="display:block; margin:0px auto 10px; text-align:center;cursor:pointer; cursor:hand;" src="http://photos1.blogger.com/blogger/7492/3170/320/ResultTools.jpg" border="0" alt="" /></a>Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com3tag:blogger.com,1999:blog-29697005.post-1150289473097943062006-06-14T05:35:00.000-07:002006-06-14T22:32:02.843-07:00Avoid Dynamic SQL when u want to use a variable in IN clauseWhen we want to filter the result set using IN clause. We end up having dynamic SQL.<br />The scenario goes like this.<br /><br />Basic Query:<br />select<br /> * --(writing * is not a god practice write down column names)<br />from<br /> employee<br />where<br /> employee_id in (100,10001,11560)<br /><br />If the give employee ids come thru a variable(viz as input param to SP). U can get the result using dynamic SQL as below.<br /><br />@strInput varchar(200)<br />set @strInput = '100,10001,11560'<br /><br />@strQuery varchar(1000)<br />set @strQuery = 'select * from employee where employee_id in (' + @strInput + ')'<br /><br />exec(@strQuery)<br /><br />We can achieve the same with out dynamic SQL. The query below will address the same.<br /><br />select * from employee where charindex(','+cast(employee_id as varchar)+',',@strInput) > 0<br /><br /><br />Note:<br /> we need to convert the employee_id to varchar so that we can ap(pre)pend ',' to the id.<br /> Why we need to add ',' to employee_id column?. (Think your self).<br /> The reason is if u have employee_id's as 1,11,1111 then without ',' will give wrong results.<br /><br />Hope you all appreciate the usage of charindex. More in the next article. Njoy reading.<br /><br />SurendraSurendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com1tag:blogger.com,1999:blog-29697005.post-1150285102752632782006-06-14T04:09:00.000-07:002006-06-14T04:38:33.636-07:00How the word 'Interface' came into OOP terminology<div style="text-align: justify;">I thought of framing the question as (why the name for Interface is interface in Object Oriented Programming) :-). What ever, Just keep OOP aside and think what is an 'interface'?. What is the interface to your home/room/office?.<br /><br /> Interface is nothing but the way an object get exposed to the external world. That means you can play around with any object by its interface only. Now come to OOPs. U can play around with an object/class using its variables and its methods only(Is it Not?). Therefore interface to(of) a class is nothing but a its(class's) variables and method signatures.<br /><br /> Now come to Interface in OOPs..Afterall interface is also a class but it just consist only the variables and method signatures. Hence A class which just contains the details of its interface is called Interface.<br /><br /><br /><br /></div>Surendra Sambanahttp://www.blogger.com/profile/12930977467468244954noreply@blogger.com8