I was wondering for those who are developing in VS2008 or higher are taking advantage of LINQ and language extensions not because they are something different but because they make development easier with consistency in coding and maintenance?
Simple everyday example makes string to integer method based
Keeping functional, reusable code behind away from business logic and novice developers and allows for easy maintenance similar to the next exampleCode:<System.Diagnostics.DebuggerStepThrough()> _ <Runtime.CompilerServices.Extension()> _ Public Function ToInteger(ByVal value As String) As Integer Return Convert.ToInt32(value) End Function
Lastly anyone using LINQ to quickly test queries as shown below?Code:<System.Diagnostics.DebuggerStepThrough()> _ <Runtime.CompilerServices.Extension()> _ Function CurrentRowCellValue(ByVal GridView As DataGridView, ByVal ColumnName As String) As String Return GridView.Rows(GridView.CurrentRow.Index).Cells(ColumnName).Value.ToString End Function
(Code below is to show a concept, I code with database classes)
Code:Using cn As New OleDb.OleDbConnection( _ "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=data\demo.mdb;") Dim da As New OleDb.OleDbDataAdapter( _ "SELECT PersonName, ContactPosition FROM People;", cn) Dim ds As New DataSet da.Fill(ds) Dim dv As DataView dv = ds.Tables(0).DefaultView dv.Sort = "PersonName" ' The following perhaps come from a textbox etc. ' in a real application Dim InsertName As String = "Jane Smith" Dim InsertTitle As String = "Manager" Dim result As Integer = dv.Find(InsertName) If result = -1 Then Console.WriteLine("Adding") cn.Open() Dim cmd As New OleDb.OleDbCommand With _ {.CommandText = _ <SQL> INSERT INTO People (PersonName, ContactPosition) VALUES (<%= InsertName.SingleQuotes %>, <%= InsertTitle.SingleQuotes %>) </SQL>.Value, _ .Connection = cn} cmd.ExecuteNonQuery() End If End Using




Reply With Quote