Wrox Programmer Forums
Go Back   Wrox Programmer Forums > .NET > Other .NET > ADO.NET
ADO.NET For discussion about ADO.NET.  Topics such as question regarding the System.Data namespace are appropriate.  Questions specific to a particular application should be posted in a forum specific to the application .
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ADO.NET section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
Old May 6th, 2005, 06:08 AM
Authorized User
Join Date: Feb 2005
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to ashokparchuri Send a message via Yahoo to ashokparchuri
Default Problem with datareader


 i am writing code like the below


  where dr is datareader and a is a variable.when i get the data into datareader this code was working properly.

    but when no data was coming from databse to datareader the code is not working.it was showing a error("reading when nodata present").

     so how can i see whether i got data into datareader or not..?

 thanks in advance-Ashok Parchuri
Old May 6th, 2005, 07:05 AM
planoie's Avatar
Friend of Wrox
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts

If dr.read() then
end if

Read() will return true until there are no more rows.

Old May 13th, 2005, 04:32 AM
vbn vbn is offline
Authorized User
Join Date: May 2005
Posts: 23
Thanks: 0
Thanked 0 Times in 0 Posts

Purpose :To retrieve data from the database using Data Reader and Data Commands. When this code is executed, the data in a database is displayed in two textbox controls.


Design a form using .NET environment and place two textbox controls on a form.
Design and create a table using SQL Server 2000.

Name the Database as FinAccounting.
Name the Table as AccountsTable.
Name the form as Form1
Name the controls on the form as Textbox1 and Textbox2.


1. Establish the connection with the Database using Connection object.
2. Execute the command.
3. The data will be read by the Datareader object and the contents of the first record is displayed in the textboxes.

Imports System.Data.SqlClient
    Public Class Form1
        Inherits System.Windows.Forms.Form
        Dim str_sql_user_select As String = “SELECT * FROM AccountsTable”
        Dim str_connection As String = “Data Source=VSDOTNET;Integrated Security=SSPI;Initial Catalog=FinAccounting”
        Dim mycon As SqlConnection
        Dim comUserSelect As SqlCommand
        Dim myreader As SqlDataReader

Private Sub Form1_Load(ByVal sender As Object, ByVal e As system.EventArgs) Handles
        mycon = New SqlConnection(str_connection)
        â€˜Instantiate the commands
        comUserSelect = New SqlCommand(str_sql_user_select, mycon)
        TextBox1.Text = “ “
        TextBox2.Text = “ “
            myreader = comUserSelect.ExecuteReader
            If (myreader.Read = True) Then
                TextBox1.Text = myreader(0)
                TextBox2.Text = myreader(1)
                MsgBox(“You have reached eof”)
            End If
        End Sub
End Class

Books for programmers

Similar Threads
Thread Thread Starter Forum Replies Last Post
DataReader Problem gaurav_jain2403 ADO.NET 5 October 10th, 2007 03:48 PM
Datareader problem is about to cause my death joer80 .NET Framework 2.0 1 June 7th, 2006 07:20 AM
Datareader problem, killing me joer80 ADO.NET 1 March 23rd, 2006 06:44 PM
DataReader problem nalla ASP.NET 1.0 and 1.1 Professional 6 February 7th, 2006 06:07 AM
Problem reading DataReader after Databind rathbird ADO.NET 1 March 10th, 2004 05:53 PM

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.