Click here to Skip to main content
15,558,870 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
In DataGridView I saved like 10:00am-01:00pm,02:00pm-03:00pm for timings column. If i click grid values,it is comint to the datatable. That's fine.
Suppose if i update some values like Age,Name etc and click update means, Gridview is having null values in Timings column.
Used this code to update again to datagridview for timing column,
Dim totaltime As String = ""
   Dim i As Integer
   For i = 0 To Carer.dt.Rows.Count - 1
     If i = 0 Then
     totaltime += Carer.dt.Rows(i)("TimeFrom").ToString() + "-" + Carer.dt.Rows(i)("TimeTo").ToString()
     Else
     totaltime += "," + Carer.dt.Rows(i)("TimeFrom").ToString() + "-" + Carer.dt.Rows(i)("TimeTo").ToString()
     End If
   Next

Please help me thanks in advance


[edit]Spurious code block removed - OriginalGriff[/edit]
Posted
Updated 10-Jun-11 9:15am
v3

1 solution

You have to make sure that the columns you're trying to extract data from are not themselves null. Keep in mind this was typed off the top of my head, so you may need to tweak it.

VB
Dim totalTime As String = ""
For i = 0 To Carer.dt.Rows.Count - 1
    Dim timeFrom as String = ""
    Dim timeTo as String = ""

    if (Not IsDBNull(Carer.dt.Rows(i)("TimeFrom")) Then
        timeFrom = Carer.dt.Rows(i)("TimeFrom").ToString()
    End If
    if (Not IsDBNull(Carer.dt.Rows(i)("TimeTo")) Then
        timeTo = Carer.dt.Rows(i)("TimeTo").ToString()
    End If

    If (Not string.IsNullOrEmpty(totalTime)) Then
        totalTime += ","
    EndIf
    totaltime += string.Format("{0}-{1}", timeFrom, timeTo)
Next


Finally, using the debugger would have help you solve the issue.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900