Home All Groups Group Topic Archive Search About

how to display records in datagrid

Author
14 Apr 2005 2:55 PM
yoshitha
hi,

i want to display records in datagrid.

strtestids() is a string array.

it contains some testids.

based on these ids i've to fill the datagrid.

i wrote code like this

  Dim db As New NESDK.DatabaseGrid


        Dim i As Integer

        For i = 0 To strTestIds.Length - 1


            If db.Run("select Testname,TestId,NoOfQues,TotalTime  from

TestInfo where testid='" & strTestIds(i) & "'") Then
                grdTests.DataSource = db.Result
                grdTests.DataBind()
            End If
        Next


here in grid am getting only the last record. i.e if my string array

contains 2 records in grid am getting last record instead of 2 records.

can any one tell me how to do this one. why am getting last record only?

Thanx in advance
Yoshitha

Author
14 Apr 2005 4:07 PM
RBrady
Yoshitha,

The code snippet you've provided calls the databind() method on each
iteration of the loop, effectively refreshing the datasource.

You might try changing your query to find a result set with all records that
have id's in your specified range.

Example:

Dim db As New NESDK.DatabaseGrid 'Some datagrid
Dim i As Integer
Dim strQuery as String

'Build Query
strQuery = "SELECT Testname,TestId,NoOfQues,TotalTime FROM TestInfo WHERE
testid IN ("

'Build IN (Values)
For i = 0 To strTestIds.Length - 1
         strQuery = strQuery & "'" & strTestIds(i) & "',"
Next

'Remove last comma
strQuery = strQuery.Remove(strQuery.Length-1,1)

'Put strQuery together
strQuery = strQuery + ")"

'Execute your databinding code
If db.Run(strQuery) Then
   grdTests.DataSource = db.Result
   grdTests.DataBind()
End If

Ryan

Show quoteHide quote
"yoshitha" wrote:

> hi,
>
> i want to display records in datagrid.
>
> strtestids() is a string array.
>
> it contains some testids.
>
> based on these ids i've to fill the datagrid.
>
> i wrote code like this
>
>   Dim db As New NESDK.DatabaseGrid
>
>
>         Dim i As Integer
>
>         For i = 0 To strTestIds.Length - 1
>
>
>             If db.Run("select Testname,TestId,NoOfQues,TotalTime  from
>
> TestInfo where testid='" & strTestIds(i) & "'") Then
>                 grdTests.DataSource = db.Result
>                 grdTests.DataBind()
>             End If
>         Next
>
>
> here in grid am getting only the last record. i.e if my string array
>
> contains 2 records in grid am getting last record instead of 2 records.
>
> can any one tell me how to do this one. why am getting last record only?
>
> Thanx in advance
> Yoshitha
>
>
>