Saturday, January 24, 2015

Useful Links - FTP Creation And Configuration

Useful Links - FTP Upload And Download

Useful Links - Image handling in web

Wednesday, May 14, 2014

DATAGRIDVIEW ROW FORMATING

SAMPLE:

Private Sub dgvData_CellFormatting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellFormattingEventArgs) Handles dgvData.CellFormatting

        If dgvData.DataSource IsNot Nothing Then
            Dim drv As DataRowView
            Dim dt As DataTable = CType(dgvData.DataSource, DataSet).Tables(0)

            If e.RowIndex >= 0 Then
                If e.RowIndex <= dt.Rows.Count - 1 Then
                    drv = dt.DefaultView.Item(e.RowIndex)
                    Dim dfm As Date

                    Dim dto  As Date
                    dfm = drv.Item("Period From")
                    dto  = drv.Item("Period Upto")                      
                    If Now.Date >= dfm And Now.Date <= dto Then
                        e.CellStyle.ForeColor = dgvData.DefaultCellStyle.ForeColor
                    Else
                        e.CellStyle.ForeColor = SystemColors.GrayText
                    End If
                End If
            End If
        End If
    End Sub

Tuesday, February 25, 2014

@@IDENTITY vs SCOPE_IDENTITY() vs IDENT_CURRENT



@@IDENTITY returns the id of the last thing that was inserted by your client's connection to the database. Most of the time this works fine, but sometimes a trigger will go and insert a new row that you don't know about, and you'll get the ID from this new row, instead of the one you want
SCOPE_IDENTITY() solves this problem. It returns the id of the last thing that you inserted in the SQL code you sent to the database. If triggers go and create extra rows, they won't cause the wrong value to get returned.
IDENT_CURRENT returns the last ID that was inserted by anyone. If some other app happens to insert another row at an unforunate time, you'll get the ID of that row instead of your one.




Following code nicely work with Sql server 2005

DECLARE @last_id INT;

INSERT INTO [my_table] ([col1],[col2])
OUTPUT INSERTED.[id] INTO @last_id
VALUES (@col1,@col2)




More Info:
http://stackoverflow.com/questions/42648/best-way-to-get-identity-of-inserted-row 

Friday, January 24, 2014

SUM OF A DATAGRIDVIEW CELL USING LINQ



SAMPLE:1

Dim qry0 = From theRow As DataGridViewRow In dgvData.Rows _
                      Select theRow
Dim t = qry0.Sum(Function(x As DataGridViewRow) x.Cells("Amount").Value)

** dgvData - Datagridview name "Anount" is column name

-----------------------------------------------------------------

SAMPLE:2

Dim qry1 = From theRow As DataGridViewRow In dgvData.Rows _
              Where theRow.Cells("Year").Value > 2010 _
              Select theRow

Dim t = qry1.Sum(Function(x As DataGridViewRow) x.Cells("Amount").Value)