Surendra Sharma

Surendra Sharma

Search This Blog

Wednesday, July 31, 2013

How to visit any particular line of code in Visual Studio

If there are lots of lines of code in a single code file and your colleagues told you to look piece of code at particular line number or any error occurred at specific line number.

How do you visit to that line of code?

By just scrolling ... that’s history

Solution :->

Some couple of handy ways to visit to particular line number in Visual studio
·         You can display line number at left side of code editor from Tools -> Options -> Text Editor -> All Languages -> Enabled Line numbers option. It should display line numbers in code editor as shown below




·         Visual Studio always display line number , column number and character position of cursor in status bar of visual studio as shown in above image

·         You also have facility to directly visit to any line number from Edit -> Go To... or press Ctrl + G as shown below


·         Use bookmarks to directly visit any particular line numbers

·         Use scroll bar to visit to particular line

·         Use keyboard Page Up or Page Down button

·         Use UP or DOWN arrow keys to navigate


Please leave your comments or share this tip if it’s useful for you.

Tuesday, July 30, 2013

How to get distinct values from column in Excel

If you have repetitive entries in excel column as below


How to get distinct values from column in Excel sheet.


Solution:-

Select column and click on Data -> Remove Duplicates
You should get output as below




Please leave your comment if it’s useful for you.

Monday, July 29, 2013

How to show more than 10 projects in Visual Studio recent project list

During working in Visual Studio (VS), we can view most recently used project in "Recent Projects" list.
However VS shows only 10 recent projects.

If we are working on multiple projects then how to show more than 10 projects in recent project list?

Solution:-

Open Visual Studio -> Go to Tools -> Options -> General -> modify value of "items shown in recently used lists".

Generally I make it 20.


Please leave your comments if it’s useful for you.

Thursday, July 25, 2013

Maximum request length exceeded

If you are getting error in Asp.Net as “System.Web.HttpException: Maximum request length exceeded This type of error mostly occurred when we are using File Upload functionality.

Due to increase in content lenth of request from the its dafult value then ASP.NET engine fires this error.


Solution: -

Open web.config file and set “maxRequestLength” key to more than the size of file.
The default size of “maxRequestLength” is 4096 KB (4 MB).
Value must be specified in KB as below

<httpRuntime maxRequestLength="10240"></httpRuntime>



10240 means 10 MB. (10 x 1024) - You can increase this up to 4 GB.

Your face is the new credit card

Are you tired to keep debit, credit cards or cash, to remembers hundreds of passwords and PIN then here is a good news. Now you don't need to remember anything. 

Please read more fro below link.

http://www.techgig.com/tech-news/editors-pick/Your-face-is-the-new-credit-card-18979

Tuesday, July 23, 2013

'Selected' is not a member of 'System.Windows.Forms.TreeNode'.

During migration from VB to VB.NET if you are getting error as "'Selected' is not a member of 'System.Windows.Forms.TreeNode'." with following type of code
  
'UPGRADE_ISSUE:Node property myTreeView.Nodes.Selected was not upgraded.
myTreeView.Nodes.Item("Item1").Selected = True

Solution: -

Use “SelectedNode” property to show child node as selected as below


myTreeView.SelectedNode = myTreeView.Nodes.Item(("Item1")

'MSCOMCTL.OCX' cound not be loadded--Continue Loading Project?

If you are getting error as "'MSCOMCTL.OCX' cound not be loadded--Continue Loading Project?"

Solution: -
It simply means that system don’t have file “'MSCOMCTL.OCX”. To fix this error follow below steps
·         Download and install VisualBasic6-KB896559-v1-ENU.exe from http://www.microsoft.com/en-in/download/details.aspx?id=10019
·         You need to restart system
·         Run following command to register MSCOMCTL.OCX component

o    regsvr32  C:\Windows\System32\MSCOMCTL.OCX

'As Any' is not supported in 'Declare' statements.

During migration from VB to VB.NET if you are getting error as "'As Any' is not supported in 'Declare' statements." with following type of code


'UPGRADE_ISSUE: Declaring a parameter 'As Any' is not supported.
Declare Function FindWindow Lib "user32"  Alias "FindWindowA"(ByVal lpClassName As String, ByVal lpWindowName As Any) As Integer

Solution: -

Find all the references of method “FindWindow” in project and check which type of values are passed to method “FindWindow”. Replace “Any” with passed value data type. If more than one data types are used then create overloaded method.


Declare Function FindWindow Lib "user32"  Alias "FindWindowA"(ByVal lpClassName As String, ByVal lpWindowName As String) As Integer

'OpenForms' is not a member of 'My.MyApplication'.

During migration from VB to VB.NET if you are getting error as "'OpenForms' is not a member of 'My.MyApplication'." 


Solution: -


Right click Project Proerties -> Application -> Checked Enable Application framework

’Value of type 'String' cannot be converted to 'System.Windows.Forms.ListViewItem.ListViewSubItem'.

During migration from VB to VB.NET if you are getting error as "’Value of type 'String' cannot be converted to 'System.Windows.Forms.ListViewItem.ListViewSubItem'." with following type of code


'UPGRADE_WARNING: Lower bound of collection mylistview.ListItems has changed from 1 to 0
'UPGRADE_WARNING: Lower bound of collection mylistview.ListItems().ListSubItems has changed from 1 to 0. 'UPGRADE_WARNING: Couldn't resolve default property of object mylistview.ListItems().ListSubItems().

mylistview.Items.Item(currentIndex).SubItems.Item(1) = "Test"

Solution: -

Use “Text” property to assign value as below


mylistview.Items.Item(currentIndex).SubItems.Item(1).Text = "Test"

’Value of type 'Microsoft.VisualBasic.FileAttribute' cannot be converted to 'System.Windows.Forms.Cursor'.

During migration from VB to VB.NET if you are getting error as "’Value of type 'Microsoft.VisualBasic.FileAttribute' cannot be converted to 'System.Windows.Forms.Cursor'." with following type of code

'UPGRADE_ISSUE: Unable to determine which constant to upgrade vbNormal to. 'UPGRADE_ISSUE: Screen property Screen.MousePointer does not support custom mousepointers.
'UPGRADE_WARNING: Screen property Screen.MousePointer has a new behavior.
System.Windows.Forms.Cursor.Current = vbNormal

Solution: -
Use “Cursors.Default” as below


System.Windows.Forms.Cursor.Current = Cursors.Default

'NewIndex' is not a member of 'System.Windows.Forms.CheckedListBox'

During migration from VB to VB.NET if you are getting error as "'NewIndex' is not a member of 'System.Windows.Forms.CheckedListBox'" with following type of code


myCheckedListBox.Items.Add("MatchName")
'UPGRADE_ISSUE: ListBox property myCheckedListBox.NewIndex was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="F649E068-7137-45E5-AC20-4D80A3CC70AC"'
myCheckedListBox.SetSelected(myCheckedListBox.NewIndex, False)

Solution: -
Store number of newly added item of CheckedListBox in some variable and use that value in place of “NexIndex” as below

Dim currentItemNumber As Integer = myCheckedListBox.Items.Add("MatchName")

myCheckedListBox.SetSelected(currentItemNumber, False)

'SelLength' is not a member of 'System.Windows.Forms.Control'.

During migration from VB to VB.NET if you are getting error as "'SelLength' is not a member of 'System.Windows.Forms.Control'." with following type of code


'UPGRADE_WARNING: Couldn't resolve default property of object mytextbox.SelLength.
mytextbox.SelLength = 0
Solution: -
Use new property “SelectionLength” as below

mytextbox.SelectionLength = 0

'SelStart' is not a member of 'System.Windows.Forms.Control'.

During migration from VB to VB.NET if you are getting error as "'SelStart' is not a member of 'System.Windows.Forms.Control'." with following type of code


'UPGRADE_WARNING: Couldn't resolve default property of object frmForm.ActiveControl.SelStart.
mytextbox.SelStart = 0
Solution: -
Use new property “SelectionStart” as below
mytextbox.SelectionStart = 0

'NewIndex' is not a member of 'System.Windows.Forms.ListBox'

During migration from VB to VB.NET if you are getting error as "'NewIndex' is not a member of 'System.Windows.Forms.ListBox'" with following type of code


mylistbox.Items.Add("MatchName")
'UPGRADE_ISSUE: ListBox property mylistbox.NewIndex was not upgraded. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="F649E068-7137-45E5-AC20-4D80A3CC70AC"'
mylistbox.SetSelected(mylistbox.NewIndex, False)

Solution: -
Store newly added item in listbox’s number in some variable and use that value in place of “NexIndex” as below
Dim currentItemNumber As Integer = mylistbox.Items.Add("MatchName")

mylistbox.SetSelected(currentItemNumber, False)

'Me' cannot be the target of an assignment.

During migration from VB to VB.NET if you are getting error as "'Me' cannot be the target of an assignment." with following type of code

'UPGRADE_NOTE: Object frmDSNs may not be destroyed until it is garbage collected. Click for more: 'ms-help://MS.VSCC.v90/dv_commoner/local/redirect.htm?keyword="6E35BFF6-CD74-4B09-9689-3E1A43DF8969"'
Me = Nothing

Solution: - Just find and replace
Me = Nothing
with
'Me = Nothing

in entire project

Friday, July 19, 2013

How to get 3 character or MMM format month name in sql server

Here is query for showing complete month name, month number and month name in MMM or 3 character format

SELECT
DATENAME(mm,GETDATE()) AS [Month Name],   -- Dispaly complete Month Name
MONTH(GETDATE()) AS [Month Number], -- Dispaly Month number as NN digit
SUBSTRING(DATENAME(mm,GETDATE()),1,3) AS Month Name In MMM  -- Dispaly Month name in 3 characters
Output:


Month Name
Month Number
Month Name In MMM
July
7
Jul

Meet the richest man who became world's only 'quadrillionaire' for a minute - thanks to PayPal error

Due to some technical error in Paypal system, this man became world richest man. 

Please read more from here 
http://in.news.yahoo.com/meet-man-became-worlds-only-quadrillionaire-minute-thanks-044313668.html

Thursday, July 18, 2013

Best number of world

The world's best number is 73 as
  • 73 is 21st prime number
  • The number 21 = 7 X 3
  • Binary representation of 21 is 10101 which is palindrome
  • Its mirror is 37 which is also prime number. 37 is the 12th prime number
  • Binary representation of 73 is 1001001 which is palindrome

Human pee to charge cellphones

Scientists developed a technology from which human urine is used to charge small electric gazettes such as mobile. Beauty of this technology is that its eco-friendly and not dependent on external factors such as sun etc.

Please read complete article from here


Wednesday, July 17, 2013

World‘s most advanced computer dumber than a five-year old

Here is interesting article about Artificial Intelligence (AI) where engineers are trying to implement commonsense functionality in computer developed by MIT.

More details are here

Tuesday, July 16, 2013

Connected my blog to GOOGLE+

Today I connected my blog to GOOGLE+ . Its cool.

How to get one desire record by using WHERE and ORDER BY clause

CreatetblSettingusing following query

/****** Object:  Table [dbo].[tblSetting]    Script Date: 07/16/2013 11:43:49 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

SET ANSI_PADDING ON
GO

CREATE TABLE [dbo].[tblSetting](
      [ID] [int] IDENTITY(1,1) NOT NULL,
      [UniversityID] [int] NOT NULL,
      [CollegeID] [int] NOT NULL,
      [cItem] [varchar](50) NOT NULL,
      [cDescription] [varchar](200) NOT NULL,
      [cValue] [varchar](200) NOT NULL
CONSTRAINT [Pk_ID] PRIMARY KEY CLUSTERED
(
      [ID] ASC
)WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) ON [PRIMARY]
) ON [PRIMARY]

GO

SET ANSI_PADDING OFF
GO


Get record according to College Level or university level or global level such that we get only one record
Conditions are

1. Get record according to college and University level i.e. where UniversityID AND CollegeID is non zero
2. Get record according to college level i.e. If 1st condition does not match then execute this where UniversityID is zero AND CollegeID is non zero
3. Get record according to University level i.e. If 1st, 2nd condition does not match then execute this where UniversityID is non zero AND CollegeID is zero
4. Get record according to global setting level i.e. If 1st, 2nd, 3rd condition does not match then execute this where both UniversityID AND CollegeID is zero

Get single record by using only one SELECT query.

I follow following way to get the desire result. Execute each condition one by one and check the result

Condition 4

Insert Following records where UniversityID AND CollegeID is zero

INSERT INTO dbo.tblSetting (UniversityID, CollegeID, cItem, cDescription, cValue) VALUES(0,0,'FileUploadPath','File Upload Path','\\XYZ\GlobalReports\')

SELECT TOP 1 * FROM tblSetting WHERE cItem = 'FileUploadPath' AND
(UniversityID = 177 OR UniversityID = 0) AND (CollegeID = 65 OR CollegeID = 0) ORDER BY CollegeID DESC , UniversityID DESC

Here our 1st, 2nd, 3rd conditions are not satisfied, however 4th condition is valid. So its output is

ID
UniversityID
CollegeID
cItem
cDescription
cValue
1
0
0
FileUploadPath
File Upload Path
\\XYZ\GlobalReports\

Condition 3

Insert Following records where UniversityID is non zero AND CollegeID is zero

INSERT INTO dbo.tblSetting (UniversityID, CollegeID, cItem, cDescription, cValue) VALUES(177,0,'FileUploadPath','File Upload Path','\\XYZ\UnivReports\')

SELECT TOP 1 * FROM tblSetting WHERE cItem = 'FileUploadPath' AND
(UniversityID = 177 OR UniversityID = 0) AND (CollegeID = 65 OR CollegeID = 0)ORDER BY CollegeID DESC , UniversityID DESC

Here 1st, 2nd, 4rd conditions are not satisfied, however 3rd condition is valid. So its output is

ID
UniversityID
CollegeID
cItem
cDescription
cValue
2
177
0
FileUploadPath
File Upload Path
\\XYZ\UnivReports\



Condition 2

Insert Following records where UniversityID is zero AND CollegeID is non zero

INSERT INTO dbo.tblSetting (UniversityID, CollegeID, cItem, cDescription, cValue) VALUES(0,65,'FileUploadPath','File Upload Path','\\XYZ\CollegeReports\')

SELECT TOP 1 * FROM tblSetting WHERE cItem = 'FileUploadPath' AND
(UniversityID = 177 OR UniversityID = 0) AND (CollegeID = 65 OR CollegeID = 0)ORDER BY CollegeID DESC , UniversityID DESC

Here our 1st, 3rd, 4th conditions are not satisfied, however 2th condition is valid. So its output is

ID
UniversityID
CollegeID
cItem
cDescription
cValue
3
0
65
FileUploadPath
File Upload Path
\\XYZ\CollegeReports\

Condition 4

Insert Following records where both UniversityID AND CollegeID is non zero

INSERT INTO dbo.tblSetting (UniversityID, CollegeID, cItem, cDescription, cValue) VALUES(177,65,'FileUploadPath','File Upload Path','\\XYZ\UnivCollegeReports\')

SELECT TOP 1 * FROM tblSetting WHERE cItem = 'FileUploadPath' AND
(UniversityID = 177 OR UniversityID = 0) AND (CollegeID = 65 OR CollegeID = 0)ORDER BY CollegeID DESC , UniversityID DESC

Here our 1st, 2nd, 3rd conditions are not satisfied, however 4th condition is valid. So its output is

ID
UniversityID
CollegeID
cItem
cDescription
cValue
4
177
65
FileUploadPath
File Upload Path
\\XYZ\UnivCollegeReports\

As you can analyze we are using same SELECT query for all output

SELECT TOP 1 * FROM tblSetting WHERE cItem = 'FileUploadPath' AND
(UniversityID = 177 OR UniversityID = 0) AND (CollegeID = 65 OR CollegeID = 0)ORDER BY CollegeID DESC , UniversityID DESC

I believe there are multiple ways of doing this in SQL Server. Let me know if you have any other way of achieving the desire result.

Please leave your comments / suggestion.