Hey.I need some help in navigating rows.Im using a DataReader to read and display data.Now im trying to navigate the data that i have retrieved and i have a proble with that

These are my codings for the retrieving part:

Dim conn As OleDbConnection
        Try
            conn = New OleDbConnection(My.Settings.ConnectionString)
            conn.Open()
            Dim asql As String = "Select * From IDM_IDEA_DATA Where TEAM_NAME='" & cboTeam.Text.Trim & "' Order By DATE_SUBMITTED Desc" ' AND IDEA_ID='" & cboID.Text & "'"
            Dim cmd As New OleDbCommand(asql, conn)
            Dim dr As OleDbDataReader
            dr = cmd.ExecuteReader()
            If dr.HasRows Then
                If dr.Read Then
                    If IsDBNull(dr(2)) = False Then
                        txtPDesc.Text = dr(2)
                    End If
                    If IsDBNull(dr(3)) = False Then
                        txtIDesc.Text = dr(3)
                    End If
                    If IsDBNull(dr(4)) = False Then
                        txtComments.Text = dr(4)
                    End If
                    If IsDBNull(dr(7)) = False Then
                        cboStatus.Text = dr(7)
                    End If
                    'If IsDBNull(dr(8)) = False Then
                    '    chkQualify.Checked = True
                    '    chkQualify.Text = dr(8)
                    'End If
                    If IsDBNull(dr(10)) = False Then
                        txtSubmitDate.Text = dr(10)
                    End If
                    If IsDBNull(dr(12)) = False Then
                        txtQualDate.Text = dr(12)
                    End If
                    If IsDBNull(dr(0)) = False Then
                        cboID.Text = dr(0)
                    End If
                End If
            End If
            Dim i As Integer
            While dr.Read
                i += 1
            End While
            dr.Close()
            conn.Close()
            Me.txtNoItems.Text = i
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try

Hope u guys can give me hand in this.
Thx

Hi,

try this


Dim conn As OleDbConnection
Try
conn = New OleDbConnection(My.Settings.ConnectionString)
conn.Open()
Dim asql As String = "Select * From IDM_IDEA_DATA Where TEAM_NAME='" & cboTeam.Text.Trim & "' Order By DATE_SUBMITTED Desc" ' AND IDEA_ID='" & cboID.Text & "'"
Dim i As Integer = 0
Dim cmd As New OleDbCommand(asql, conn)
Dim dr As OleDbDataReader
dr = cmd.ExecuteReader()

If dr.HasRows Then
While dr.Read
If IsDBNull(dr(2)) = False Then
txtPDesc.Text = dr(2)
End If
If IsDBNull(dr(3)) = False Then
txtIDesc.Text = dr(3)
End If
If IsDBNull(dr(4)) = False Then
txtComments.Text = dr(4)
End If
If IsDBNull(dr(7)) = False Then
cboStatus.Text = dr(7)
End If
'If IsDBNull(dr(8)) = False Then
' chkQualify.Checked = True
' chkQualify.Text = dr(8)
'End If
If IsDBNull(dr(10)) = False Then
txtSubmitDate.Text = dr(10)
End If
If IsDBNull(dr(12)) = False Then
txtQualDate.Text = dr(12)
End If
If IsDBNull(dr(0)) = False Then
cboID.Text = dr(0)
End If
i += 1
End While
End If

txtNoItems.Text = i

dr.Close()
conn.Close()

Catch ex As Exception
MsgBox(ex.Message)
End Try

Hi,

There is WHILE loop to read the records
i.e. WHILE dr.read()

so it will read all the records one by one

it will read one by one but i need to show it one by one by putting a button to go to the next row.
how can i do this?

Try this

DataSet objDs;
int i = 0;


protected void Button1_Click(object sender, EventArgs e)
{
if (i == 0)
{
GetDataSet(cmdtext,context);
}
ShowRecord(i);
i += 1;



}


private void GetDataSet(string commandText, string ConnectionStringSettings)
{
SqlDataAdapter objSqlDataAdapter = new SqlDataAdapter(commandText, ConnectionStringSettings);
objSqlDataAdapter.Fill(objDs);
}


private void ShowRecord(int i)
{
TextBox1.text = objDs.Tables[0].Rows["colname"].ToString();
-
-
-
-
}

Edited 3 Years Ago by happygeek: fixed formatting

i've tried converting it to vb but it doesn't work.
can u convert this to vb?
thx alot

Dim i As Integer = 0
Dim searchID As String = txtID.Text
Dim cmd1 As String = "Select * From IDM_IDEA_DATA Where IDEA_ID='" & searchID & "' Order By DATE_SUBMITTED Desc"
Dim conn1 As String = My.Settings.ConnectionString
Dim ds1 As New DataSet
Dim da1 As New OleDbDataAdapter(cmd1, conn1)

Private Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
If i = 0 Then
Call getDS(cmd1, conn1)
End If
Call showRecord(i)
i += 1
End Sub

Private Sub getDS(ByVal cmd1, ByVal conn1)
da1.Fill(ds1)
End Sub

Private Sub showRecord(ByVal i)
txtPDesc.Text = ds1.Tables(0).Rows(i).Item(2).ToString
End Sub

here u go

This article has been dead for over six months. Start a new discussion instead.