Wrox Programmer Forums
|
ASP.NET 2.0 Basics If you are new to ASP or ASP.NET programming with version 2.0, this is the forum to begin asking questions. Please also see the Visual Web Developer 2005 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 2.0 Basics 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 April 7th, 2007, 10:44 AM
Authorized User
 
Join Date: Dec 2006
Posts: 36
Thanks: 1
Thanked 0 Times in 0 Posts
Send a message via Yahoo to deb1980
Default Nested query

Hi,

I have been trying to write a nested query, however there are runtime errors.
The code is as below:

<%
    Dim MyConnection = New SqlConnection()
    MyConnection.ConnectionString = ConfigurationManager.ConnectionStrings("AppConnect ionString1").ConnectionString

    MyConnection.Open()

    Dim cmd As New SqlCommand

    Dim rs As SqlDataReader
    Dim rs2 As SqlDataReader

    Dim query = "select count(bank_id) from bank_master"
    Dim query2 As String

    cmd.CommandType = CommandType.Text

    cmd.Connection = MyConnection

    cmd.CommandText = query

    rs = cmd.ExecuteReader

    If rs.Read() Then
    Dim rec = rs(0)
    If (rec > 0) Then
        Response.Write(rec & " banks registered in the system")
        rs.Close()

        query2 = "select * from bank_master order by bank_id"
        rs2 = cmd.ExecuteReader(query2)
        If rs2.Read() Then
        Response.Write(rs2(0))
        Else
        Response.Write("No banks yet registered in the system")
        End If
    Else
        Response.Write("No banks yet registered in the system")
    End If
    End If
%>

The error that i am getting is :

Server Error in '/Accounts' Application.
--------------------------------------------------------------------------------

Input string was not in a correct format.
Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

Exception Details: System.FormatException: Input string was not in a correct format.

Source Error:


Line 117:
Line 118: query2 = "select * from bank_master order by bank_id"
Line 119: rs2 = cmd.ExecuteReader(query2)
Line 120: If rs2.Read() Then
Line 121: Response.Write(rs2(0))


Source File: E:\WEBHOME\Accounts\bank.aspx Line: 119


Could you please help?


---
Best regards,

Debashis
__________________
---
Best regards,

Debashis
http://debashis80.spaces.live.com/
 
Old April 8th, 2007, 10:36 PM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

I don't see anything wrong with the query you are trying to use.

Despite that however, this should be failing for a different reason: you can't have 2 data readers open at the same time.

Also, reviewing your code, I'd say you are making this more complicated than it needs to be. You are first asking for a count of records, then asking for the records. Why not just ask for the records? You'll know if you get no records back because .Read() will be false.

-Peter
 
Old April 10th, 2007, 04:38 AM
Registered User
 
Join Date: Mar 2007
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via AIM to johnysouriar
Default

bcoz two data readers open simulteneously thats y.

johny

Johny Souriar





Similar Threads
Thread Thread Starter Forum Replies Last Post
Nested Query Help Needed Corey Access 2 April 26th, 2006 02:17 PM
Nested Query or Join? rlull SQL Server 2000 4 November 10th, 2005 05:23 PM
Nested Query teclo MySQL 1 March 22nd, 2005 07:20 AM
Nested Query BrianWren Oracle 5 February 1st, 2005 01:45 PM
Nested Query Trouble ashley_y ADO.NET 2 December 23rd, 2003 01:32 PM





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