Hi all,
actually i want to populate datagridview and it's include with date. i used calendar cell as in http://msdn.microsoft.com/en-us/library/7tas5c80.aspx.
now want to show date from database into the calendar cell. this is my coding to populate the information from the database.
Private Sub PopulateData()
Dim DBClass As New clsDB.clsDatabase
DBClass.DBServer = DBPath
Dim sQuery As String = "SELECT Cards.CardNo AS [Card No], Personnel.Name AS [Name], Cards.Expiry_Date AS [Door & Lift Expiry Date], CP_Card.ExpiryDate AS [Car Park Expiry Date], " & _
"Cards.AccTag AS [Door Access Rights], Cards.LiftAccTag AS [Lift Access Rights], Personnel.StaffNo, CP_Card.SendBit " & _
"FROM Cards LEFT OUTER JOIN Personnel ON Cards.StaffNo = Personnel.StaffNo " & _
"LEFT OUTER JOIN CP_Card ON Cards.CardNo = CP_Card.CardNo " & _
"ORDER BY Cards.CardNo "
Dim dsBlock_Ext As New DataSet()
Try
If Not DBClass.ExecuteSQLTable(sQuery, dsBlock_Ext) Then
MsgBox("Unable to retrieve information from database!", MsgBoxStyle.Exclamation, FrmTitle)
LOG.WriteErrLog(0, "fBlock_Extend - PopulateDataGrid : Failed to retrieve info from database <" & sQuery & ">")
Exit Sub
End If
With dsBlock_Ext.Tables(0)
.Columns.Add("Car Park Access Rights")
If .Rows.Count > 0 Then
ReDim SearchList(.Rows.Count - 1)
ReDim aStfNo(.Rows.Count - 1)
For icnt As Integer = 0 To .Rows.Count - 1
For jcnt As Integer = 0 To .Columns.Count - 1
If jcnt = 1 Then
.Rows(icnt).Item(jcnt) = Trim(.Rows(icnt).Item(jcnt))
ElseIf jcnt = 2 Or jcnt = 3 Then
If .Rows(icnt).Item(jcnt) Is Convert.DBNull Then
.Rows(icnt).Item(jcnt) = ""
Else
.Rows(icnt).Item(jcnt) = Mid(.Rows(icnt).Item(jcnt), 7, 2) & "/" & _
Mid(.Rows(icnt).Item(jcnt), 5, 2) & "/" & _
Mid(.Rows(icnt).Item(jcnt), 1, 4)
dt = Convert.ToDateTime(.Rows(icnt).Item(jcnt), m)
End If
ElseIf jcnt = 4 Then
.Rows(icnt).Item(jcnt) = GetDoorAccess(Trim(.Rows
(icnt).Item(0)))
ElseIf jcnt = 5 Then
If .Rows(icnt).Item(jcnt) Is Convert.DBNull Then
.Rows(icnt).Item(jcnt) = ""
Else
.Rows(icnt).Item(jcnt) = Trim(.Rows(icnt).Item(jcnt))
End If
ElseIf jcnt = 6 Then
.Rows(icnt).Item(jcnt) = Trim(.Rows(icnt).Item(jcnt))
aStfNo(icnt) = .Rows(icnt).Item(jcnt)
ElseIf jcnt = .Columns.Count - 2 Then
If .Rows(icnt).Item(jcnt) Is Convert.DBNull Then
.Rows(icnt).Item(jcnt + 1) = ""
Else
.Rows(icnt).Item(jcnt + 1) = GetCPAccess(Trim(.Rows(icnt).Item(0)))
End If
Else
If .Rows(icnt).Item(jcnt) Is Convert.DBNull Then
.Rows(icnt).Item(jcnt) = ""
Else
.Rows(icnt).Item(jcnt) = Trim(.Rows(icnt).Item(jcnt))
End If
End If
Next
Next
End If
.Columns.Remove("SendBit")
.Columns.Remove("StaffNo")
End With
dgvBlock_Extend.DataSource = dsBlock_Ext.Tables(0)
Dim col As New GridDateControl()
Me.dgvBlock_Extend.Columns.Add(col)
col.Name = "Door & Lift Expiry Date"
Dim row As DataGridViewRow
For Each row In dgvBlock_Extend.Rows
row.Cells(7).Value = dt
Next row
Catch ex As Exception
LOG.WriteErrLog(0, "Block & Extend - Populate Data Grid : " & ex.Message)
Finally
DBClass.Close()
End Try
End Sub
hope anyone can help me. or if there is another solution, please tell me.
thanks!