Lessons i have learnt..

Lessons i have learnt while working **45

# using the Datetime.now is something bulls**t.. just get the datetime.now in utc format & convert back to your time zone.
Why ??
So that you are safe and make sure the created date, optin date are same as your time zone regardless to the server time..

# if two things doing same job but slightly different way, then try to use a single class library
Why ??
So that you dont need to change the code for every single time & at every single place.

# Think before hardcoding anything in ur code.. Just use config files for system values & resource files for messages.
Why ??
Bcos, u dont know when these values will get change. You dont think so, but it will happen.. May be bcos of the grammer/type error.. Or may be the requirement chane or... something else change lah.. btw its good for change management too.. 

# Please clear the SESSION/VIEWSTATE values, after it serves it purpose and also at the inital page_load
Why ??
You will be freaked out.. when user/test is done with the session & click the back button do some s**t things and break your code.. 

Check all,Select all checkbox in gridview asp.net c#


Check all,Select all checkbox in gridview asp.net

Header checkbox to select all the check box in the particular grid.

Place the below script inside the head tag
	
Include the below checkbox in your gridview:
	
		
	
	 

HOW TO TRACK STORED PROCEUDRE, TABLE, FUNCTION ALTERATION IN SQL SERVER ?


HOW TO TRACK STORED PROCEUDRE, TABLE, FUNCTION ALTERATION IN SQL SERVER ?

CREATE TABLE [dbo].[AdministratorLog](
[databasename] [varchar](256) NULL,
[eventtype] [varchar](50) NULL,
[objectname] [varchar](256) NULL,
[objecttype] [varchar](25) NULL,
[sqlcommand] [varchar](max) NULL,
[loginname] [varchar](256) NULL,
[createdon] [datetime] NULL
)

GO  

CREATE TRIGGER [Admin_Backup_Objects]
ON DATABASE
FOR create_procedure, alter_procedure, drop_procedure,
create_table, alter_table, drop_table,
create_function, alter_function, drop_function
AS
SET NOCOUNT ON
DECLARE @data XML
SET @data = EVENTDATA()

INSERT INTO dbo.AdministratorLog(databasename, eventtype,objectname, objecttype, sqlcommand, loginname,createdon)
VALUES(
@data.value('(/EVENT_INSTANCE/DatabaseName)[1]', 'varchar(256)'),
@data.value('(/EVENT_INSTANCE/EventType)[1]', 'varchar(50)'),  -- value is case-sensitive
@data.value('(/EVENT_INSTANCE/ObjectName)[1]', 'varchar(256)'), 
@data.value('(/EVENT_INSTANCE/ObjectType)[1]', 'varchar(25)'), 
@data.value('(/EVENT_INSTANCE/TSQLCommand)[1]', 'varchar(max)'), 
@data.value('(/EVENT_INSTANCE/LoginName)[1]', 'varchar(256)'),GETDATE()
)

GO


Thanks to Deeraj & dotnetfunda



BULK INSERT CSV OR TEXT FILE TO SQL TABLE


Run following script to load all the data from CSV to database table. If there is any error in any row it will be not inserted but other rows will be inserted.
BULK
INSERT 
CSVTest

FROM 'c:\csvtest.txt'
WITH(
FIELDTERMINATOR ';',
ROWTERMINATOR '\n')
GO

--Check the content of the table.
SELECT FROM CSVTest

GO

For more details click here

The selected file is a solution file but was created by a newer version of this application and cannot be opened 2012 to 2010


The selected file is a solution file but was created by a newer version of this application and cannot be opened 2012 to 2010

Error when i'm trying to open VS 2012 project in VS 2010


Tried with the below approach, it worked out. But i'm not sure this is a best way to do.Take a risk, do it..





  • Just open the solution in a text editor 
  • in the second line you can find Microsoft Visual Studio Solution File, 
  • Format Version 12.00 
  • Try to open the solution and it works.
  • change the version to 11.00 and save it.


sql connection string c#


Standard Security
   
Server=myServerAddress;Database=myDataBase;User Id=myUsername;Password=myPassword;


Trusted Connection
   
Server=myServerAddress;Database=myDataBase;Trusted_Connection=True;


Connection to a SQL Server instance
The server/instance name syntax used in the server option is the same for all SQL Server connection strings.
   
Server=myServerName\myInstanceName;Database=myDataBase;User Id=myUsername;
Password=myPassword;


Keep ur coding aside.. Relax for some time..