C# – Read, Insert, Update, Delete From SQL Database

static void Read() { try { string connectionString = "server=.;" + "initial catalog=employee;" + "user id=sa;" + "password=sa123"; using (SqlConnection conn = new SqlConnection(connectionString)) { conn.Open(); using (SqlCommand cmd = new SqlCommand("SELECT * FROM EmployeeDetails", conn)) { SqlDataReader reader = cmd.ExecuteReader(); if (reader.HasRows) { while (reader.Read()) { Console.WriteLine("Id...
Continue reading

StrorProcedure To Generate Data Provider Class From Table

************** Execute StoreProcedure **************** sp_CreateDataProviderFromTable 'Tablename', 'name' ************** StoreProcedure to store *************** CREATE proc [dbo].[sp_CreateDataProviderFromTable] ( @TableName NVARCHAR(50), @MethodName varchar(100) ) as DECLARE @ProtdVars VARCHAR(max),@PublicProps VARCHAR(max), @CMDProps VARCHAR(max), @InsertStmt VARCHAR(max), @UpdateStmt VARCHAR(max) DECLARE @PublicProps2 VARCHAR(max), @CMDProps2 VARCHAR(max),@CMDProps3 VARCHAR(max) , @PublicProps3 VARCHAR(max), @DRProps Varchar(max), @DRProps4 varchar(max), @DRProps2 varchar(max),@DRProps3 varchar(max)...
Continue reading

Store Procedure To Generate Class From Table

*********** Execute StoreProcedure ********************** sp_GenerateClassFromTable 'TableName' *********** StoreProcedure to store ********************* CREATE proc [dbo].[sp_GenerateClassFromTable] ( @TableName NVARCHAR(50) ) as DECLARE @ProtdVars NVARCHAR(max),@PublicProps NVARCHAR(max), @CMDProps NVARCHAR(max), @InsertStmt NVARCHAR(max), @UpdateStmt NVARCHAR(max) Declare @MyString nvarchar(max), @NewLineChar AS CHAR(2) SET @NewLineChar = Char(13) + CHAR(10) DECLARE @ColName NVARCHAR(20), @ColType NVARCHAR(10) DECLARE @Value...
Continue reading


Join 901 other subscribers