Posts

Showing posts from 2017

Better way of handling: Part -1

Image
Better way of handling: Part  -1  Some time back I was Doing troubleshooting for one my colleague. Came across code which could have written in better was Sample Code which was earlier written Problems with above code : Change in value will fail the Logic. As Source is Hardcoded. Change in Value will have to replicate in multiple places. After  some fine tune code changed as shown below Benefits : Change in Enum will auto affect all code. No change to be anywhere. No Hardcoded String value to be checked. Type Safety.

Lambda Expression for Search in Object

Lambda Expression for Search in Object Code for Same is below Public Class Form27     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click         Dim student As NStudent = New NStudent() With {.StudentID = 1, .StudentName = "John", .Age = 13}         Dim isStudentTeenAger = Function(s) s.Age > 12 And s.Age < 20         Console.WriteLine(isStudentTeenAger(student))     End Sub End Class Public Class NStudent     Private _studentID As Integer     Private _studentName As String     Private _age As Integer     Property StudentID() As Integer         Get             Return _studentID         End Get         Set(ByVal Value As Integer)             _studentID = Value        ...

Panel Vs GroupBox

Panel Vs GroupBox Panel has Scrollbar  Groupbox Doesn't Have Panel Provide TabStop Feature Group Box Doesn't GroupBox Border Can't be removed Panel Border are Optional Groupbox Provide Option to have Caption  Panel Doesn't

SQL Bulk Copy with Mysql Datatable to MsSql Database

SQL Bulk Copy with Mysql Datatable to MsSql Database SQLClient and MYSQLCLient Class are used for This Sample  Add namespace for  SqlBulkCopy App Config File Changes           Form level Changes to be Done Public Class frmMySQLDataImportTest     Dim cnMySQL As New MySql.Data.MySqlClient.MySqlConnection     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click        Dim sqlTrn As SqlTransaction = Nothing         Try                     'Connection String is Stored in Application Config File Dim strConnection As String =    System.Configuration.ConfigurationManager. ConnectionStrings("MySql").ToString             cnMySQL = Ne...

Multiple Connection from Config File

Config File Change     AppDB_1 ;Data Source= MyPC\Sql2008 " />     AppDB_2 " connectionString="Password= 123456 ;Persist Security Info=False;User ID=sa;Initial Catalog= AppDB_2 ;Data Source=MyPC\Sql2008" />    Front End Change Dim strConnection As String = System.Configuration.ConfigurationManager.ConnectionStrings(" AppDB_1 ").ToString cnAppDB_1 = New SqlClient.SqlConnection(strConnection) cnAppDB_1 .Open() System.Configuration.ConfigurationManager.ConnectionStrings(" AppDB_2 ").ToString cnAppDB_2  = New SqlClient.SqlConnection(strConnection) cnAppDB_2 .Open()

SqlConnectionStringBuilder Clas

Provides a simple way to create and manage the contents of connection strings used by the  SqlConnection  class. need Password stored in Connection Object {SQlclient -> SqlConnetion}. No, you can't as SqlConnection Object Doesn't have Property to Return Password Stored. To Overcome this you can use, SQLConnectionStringBuilder Class.  Code to do so Dim builder As New SqlConnectionStringBuilder(strConnection) Dim  ConnUser, ConnPassword  as String ConnUser = builder.UserID ConnPassword = builder.Password

While Looping - SQL SERVER

DECLARE @StartDate AS DATE='2014-12-17'; DECLARE @EndDate AS DATE='2014-12-25'; CREATE TABLE #DateList(iDate DATE,iDayName VARCHAR(10)) WHILE (@StartDate<=@EndDate) BEGIN                 INSERT #DateList(iDate,iDayName) VALUES(@StartDate,DATENAME(DW,@StartDate))                 SET @StartDate=CAST(DATEADD(DAY,1,@StartDate) AS DATE) END SELECT iDate AS [Date], iDayName AS [DayName] FROM #DateList

Alternative to Like Condition

DECLARE @Acc TABLE ( ID  int, AccountName Varchar(200) ) Insert into @Acc (ID,AccountName)  Values (1,'Switin Kotian'),(2,'Jitesh Shiyal'),(3,'Ramesh Bangera'),(4,'Shrikant Chavan'),(5,'Dipti Patil'),(6,'Bhavin Asher'),(7,'Smruti Kotian') Select * From @Acc Select * From @Acc Where AccountName Like 'S%' Select * From @Acc Where CharIndex('S',AccountName) = 1 Select * From @Acc Where Left(AccountName,1) = 'S' Select * From @Acc Where SUBSTRING(AccountName,1,1) = 'S'

User Defined Table Type

Drop Proc spGetColumnDetailsForTable  GO Drop Type CustParam --User defined Type {Table} Create Type CustParam as Table ( Name varchar(100), ID int ) Go -- SP to have UDT as Parameter . Readonly Keyword is Compulsary when UDT is used Create Proc spGetColumnDetailsForTable  @Para CustParam  READONLY as -- Below Syntax when you need to read Values from UDT --This return only First Value in Data Set --Declare @Name as Varchar(100) --Select @Name=Name  From @Para --Select @Name --This return only First Value in Data Set --Select * From sys.objects  objs  Where  objs.name in ( @Name) -- UDT is Used as Table to Hit join Select * From sys.objects  objs   inner join @Para Pr on Pr.id  = objs.object_id GO --- Sample for using UDT  Declare @T as CustParam Insert into  @T (Name,ID) Select name,object_id From Sys.Objects Where name Like 'T%' ---Select * from @T Exec spGetColumnDetailsForTab...

Inheritance Sample

Public Class Form1     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load     End Sub     Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click         Dim Car As New Cars         Car.Engine = "Renault"         Car.SeatingCapacity = 5         Car.BHP = 5000         Car.Color = Color.Black         Car.Type = InheritanceSample.Cars.CarType.Sedan  'This from Child Class         Car.GetMaxSpeed()  ' Will Return 0         Dim Bus As New Buses         Bus.Engine = "VOLVO"         Bus.SeatingCapacity = 25         Bus.BHP = 8000         Bus.Color = Color.Yellow         Bus.IsFrontLoadingEngine = False 'This from Child Class ...

Shared / Static Class in vb.net/C#

Image
Shared / Static Class in vb.net/C# VB.net     : Shared C#            : Static You can’t create object of Shared Class Below Image show Properties and Method are not visible for Shared/Static Class Public Class Form1     Private Sub Button1_Click(sender As Object , e As EventArgs ) Handles Button1.Click         'Module is VB.net are Shared Type Class.         'Shared Class Example is ARC.Tools.GRIDManager         'When Class s Defined as Shared There no need to create object of Class.         'If you just want to create a class that you can't inherit, in C# you can use         ' Sealed, and in VB.Net use NotInheritable.         'The VB.Net equivalent of s...