Posts

Showing posts from June, 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