Posts

How to update Row which is not having Primary Key?

We all find some different scenario where the table has no primary key column and need to update the records having same data. For this type of scenario's we need to update the particular column based on some Unique value.In SQL Server we have a option called " ROW_NUMBER() " .Every one know about Row_Number() I will present a brief intro about this. ROW_NUMBER():   ROW_NUMBER to find the Row number of a particular column if its specified in orderby Clause.It has the following syntax  Syntax: select  row_number() over (order by name) as ROWNumber, Name from sys.all_objects order by name  For more details about the R OW_NUMBER() refer this MSDN .   Here I will present a example query to update a table which has no primary key and having same data for few rows . WITH Record AS (select  row_number() over (order by [columnName]) as ROWNumber, Name from sys.all_objects order by name )  UPDATE Record set [col1]=@col1,[co...

Programmatically Zip and UnZip the files in .NET

Normally we may find the functionality to Zip and Unzip the file pro grammatically.We have many third party components to do this operation.Here I am going to present Zip and Unzip files using "CGZipLibrary.dll" in C#.NET. To do this we need to download the CGLibrary.dll from this link and register this dll. The zip file contains 3 DLL's: CGZipLibrary.dll zip32.dll Unzip32.dll Open the command prompt in administrator mode.Now we need to register this CGZipLibrary.dll as given below regsvr32 filepath\filename Ex : regsvr32 D:\Download\CGLibrary.dll After registering the dll and Copy zip32.dll and unzip32.dll to c:\windows\system32 directory or c:\winnt\system32. Unzip the file you need to do like this            string SrcPath = @"D:\StudentReports.zip";             string DestPath = @"D:\ZippedFiles";          ...

Bind the Events to the Dynamically Created Rows in a HTML Table

I found a solution to bind the events to the dynamically created buttons in a HTML.Some times we need to add a row to the existing HTML table with some inputs.That dynamically created row is not visible in the page source.Try It ! So to attach the events also we need to do like this var newRow = " <tr> <td></td> <td><input type='text' id='tbNameDyn'/></td> <td> <input type='text' id='tbAgeDyn'/>< /td> <td><input type='checkbox' id='tbResultDyn'/></td> <td > <input type='submit' name='submitButton' value='Save Row' id='btnSaveRowDyn' onclick='DynButtonClick();'> </td></tr> " ; // $('#webgrid > tbody:last'). $ ( '#webgrid tbody:last' ) . append ( newRow ) ; Here I have binded the button with the event "onClick" function ...

Make the Textbox as Label using CSS

This is a simple tip to make the textbox as label in the Web Pages.We need to just add a simple CSS to the input text.See code snippet . textboxAslabel { border : none ; background-color : # FFF ; border-color : # FFF ; } Here I have mentioned the background-color and border-color as "white".In my application the background-color is white.So according to your background-color change it.Now Apply that to the textbox.See this Image

Single to handle multiple "Submit" button Clicks in MVC3 Razor View

Last week, I have faced a problem on handling the multiple "Submit"   buttons clicks in a View.I am not very good at MVC3 but I want to share my experience so that others can find some solution regarding this problem. Suppose we have many Submit buttons in a View where we want to handle the different functions. In the Controller of the We need to write the Code for different submit buttons as given below [ AcceptVerbs ( HttpVerbs . Post ) ] public ActionResult FormActions ( string submitButton ) { switch ( submitButton . ToLower ( ) ) { case " click to know date " : this . SetNotification ( DateTime . Now . Date . ToString ( " dd-MMM-yyyy " ) ,   NotificationEnumeration . Success , true ) ; return View ( " index " ) ; break ; case " click to know time " : ...

Difference between the SCOPE_IDENTITY(),@@IDENTITY and IDENT_CURRENT in Sql Server

SCOPE_IDENTITY(),@@IDENTITY and IDENT_CURRENT('table_name') are the SQL SERVER Functions which will return the last inserted record Identity Value. Normally in the development stage we need to get the last inserted row information using SQL Query. Lets go in deep to understand the differences between these three functions. @@IDENTITY : @@IDENTITY will return the Identity value generated in a table irrespective of the scope.The main advantage lies here when we have a trigger on a table that causes anidentity to be created in another table,you will get the identity that was created last since it gets the identity regardless of the table. Syntax : SELECT @@IDENTITY; SCOPE_IDENTITY(): SCOPE_IDENTITY() also returns the Identity Value generated in a table with in the same scope regardless of the table that produced the value. Syntax: SELECT SCOPE_IDENTITY(); IDENT_CURRENT('table_name'): It will returns the last Identity value produced in a table regardle...

Set the Default Value to the Column Of a Table Programmaticaly

Normally we face this type of problem when we want to set the column default value pro-grammatically. To Solve this problem we need to first get the table column information using this Query. "SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='person'" . Here the table name may vary. when we execute this Query we will get the each column information . So based on this we can Iterate the each column and get the each column Information as given below        VB.NET  Private Sub Initialise_The_Table(ByVal ReqTab As String) On Error GoTo handle_error Dim eachTableAdapter As SqlDataAdapter Dim tableDataset As New DataSet Dim adoHelper As SQLHelper = SQLHelper.GetInstance eachTableAdapter = adoHelper.GetAdapter("SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME = '" + ReqTab + "'") eachTableAdapter.FillSchema(tableDataset, SchemaType.Source, ReqTab) eachTableA...