Posts

Showing posts from 2008

How to create the data table from dataview in c#

public static DataTable DataViewAsDataTable(DataView dv) { DataTable dt = dv.Table.Clone(); foreach (DataRowView drv in dv) dt.ImportRow(drv.Row); return dt; }

Rename DB, Table, Column,Stored Procedure,Index, View, Trigger

To rename database sp_renamedb 'Oldname', 'NewName' orsp_rename 'Oldname', 'NewName', 'DATABASE'; To rename Table column EXEC sp_ rename 'Table.Oldcolumn', 'Table.Newcolumn','COLUMN'; Example: rename object Test1 to Test2 . sp_rename 'dbo.Test1', 'Test2', 'OBJECT'; Example: rename an index from Test1 to IX_Test1 sp_rename 'dbo.Test.Test1', 'IX_test1', 'INDEX';

SMTP Authentication With The MailMessage Class

SMTP Authentication With The MailMessage Class http://www.eggheadcafe.com/PrintSearchContent.asp?LINKID=622

Get the nth highest salary using Sql Server 2005

CREATE TABLE #Employees (EmpID int, EmpName varchar(10), Salary int) INSERT #Employees SELECT 1,'Tim',345345 INSERT #Employees SELECT 2,'Jill',76845 INSERT #Employees SELECT 3,'Kathy',234545 INSERT #Employees SELECT 4,'Jack',74564 INSERT #Employees SELECT 5,'Harry',56756456 INSERT #Employees SELECT 6,'Arnol',75675 INSERT #Employees SELECT 7,'Dave',76566 INSERT #Employees SELECT 8,'Zinnade',58776 INSERT #Employees SELECT 9,'Iflar',345567 INSERT #Employees SELECT 10,'Jimmy',76766 SELECT EMPNAME,SALARY, ROW_NUMBER() OVER(ORDER BY SALARY DESC)AS TOPSALARY FROM #Employees SELECT EmpName, Salary FROM ( SELECT EMPNAME,SALARY, ROW_NUMBER() OVER(ORDER BY SALARY DESC)AS TOPSALARY FROM #Employees)TMP WHERE TOPSALARY=5 DROP TABLE #Employees

How to get the records while Inserting, updating and deleting in sql server 2005

There are three default inbuild tables, they are inserted, deleted. For both insert and update commands, the affected values are stored into inserted table and for delete command, the affected values are stroed into deleted . Example for insert. UPDATE Emp SET emp_present=1 output Inserted.* DELETE FROM emp output deleted.*

How to read the web.config file in console application

create a C# VS2005 Console application that read a web.config file to get a connection string and connect to a database, open the web.config using visual studio and save as in the bin directory with consoleapplication name. For example if console application name is myapp then config file name called myapp.exe.config, then using ConfigurationManager.ConnectionStrings can read the string values from the config. files.

How to get the latest file in the directory based up on the creation time using vc#.net

public static void GetlatestFilesList(String DirPath) { DirectoryInfo di = new DirectoryInfo(DirPath); if (di.Exists) { FileInfo[] rgFiles = di.GetFiles(SearchPattern, SearchOption.TopDirectoryOnly); //Sort the file based upon the creation time int i,j; for (i = 0; i rgFiles[j].CreationTime) { FileInfo fiTmp = rgFiles[i]; rgFiles[i] = rgFiles[j]; rgFiles[j] = fiTmp; } } } //Based upon the latest file we need to read the data foreach (FileInfo fi in rgFiles) { Console.WriteLine("FileName" + fi.Name + " Creation Time" + fi.CreationTime); } } else { Console.WriteLine("Could not find the Directory: {0}.", DirPath); } }