473,325 Members | 2,771 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

Datareader within Another Datareader

Hi all
am working on asp.net

how to use multi datareaders with in one another

please give urgent reply

thankyou
Jun 7 '08 #1
7 1024
CyberSoftHari
487 Expert 256MB
Explain your problem in detail followed by frontend and its versions.
Jun 7 '08 #2
Explain your problem in detail followed by frontend and its versions.

am using .net 2.0 with sql2005

am using two tables Supp_Purchase_Indent_Dtl and supp_purorder_dts_tbl

whilee inserting all the records inthe Supp_Purchase_Indent_Dtl having perticular jobno have to insert into supp_purorder_dts_tbl

for i wrote the following code but getting error as datareader already open please close it

if we close datareader it doesnot repeating loop



c.con.Open()
c.cmd = New SqlCommand("select * from Supp_Purchase_Indent_Dtl where job_no=" & hav, c.con)
c.dr = c.cmd.ExecuteReader()
While c.dr.Read()
Dim i As Integer
i = c.dr("requ_dtl_id")

c.cmd2 = New SqlCommand("select * from Supp_Purchase_Indent_Dtl where requ_dtl_id=" & i, c.con)
c.dr1 = c.cmd2.ExecuteReader()
If c.dr1.Read() Then
If c.dr1("item_qty") Is DBNull.Value Then
qty = ""
Else
qty = c.dr1("item_qty")
End If
If c.dr1("rate") Is DBNull.Value Then
rate = ""
Else
rate = c.dr1("rate")
End If
If c.dr1("item_qty_unit") Is DBNull.Value Then
unit = ""
Else
unit = c.dr1("item_qty_unit")
End If
If c.dr1("item_id") Is DBNull.Value Then
item = ""
Else
item = c.dr1("item_id")
End If
End If
c.dr1.Close()


c.cmd = New SqlCommand("select IsNull(Max(po_detail_id),0)+1 from supp_purorder_dts_tbl", c.con)
piid = c.cmd.ExecuteScalar()


Dim a As String = ""
a = a & "insert into supp_purorder_dts_tbl(po_detail_id,po_id,item_id,s upp_qt_id,po_item_qty,"
a = a & "po_item_rate,po_item_unit)values(" & piid & "," & c.id & "," & item & "," & qtid & ","
a = a & qty & "," & rate & ",'" & unit & "')"
c.cmd5 = New SqlCommand(a, c.con)
c.cmd5.ExecuteNonQuery()
End While
c.dr.Close()
c.con.Close()
Jun 7 '08 #3
CyberSoftHari
487 Expert 256MB
You should make your code simple.
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO supp_purorder_dts_tbl(po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit) SELECT po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit FROM Supp_Purchase_Indent_Dtl where requ_dtl_id=" & i
No need of thismany validations.
Note: You should read basic ADO.Net, You should do all the validations in query itself.
follow below concept.
Expand|Select|Wrap|Line Numbers
  1. Open reader1
  2. While
  3. Open reader2
  4. Close reader2
  5. End while
  6. Close reader1
Jun 7 '08 #4
You should make your code simple.
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO supp_purorder_dts_tbl(po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit) SELECT po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit FROM Supp_Purchase_Indent_Dtl where requ_dtl_id=" & i
No need of thismany validations.
Note: You should read basic ADO.Net, You should do all the validations in query itself.
follow below concept.
Expand|Select|Wrap|Line Numbers
  1. Open reader1
  2. While
  3. Open reader2
  4. Close reader2
  5. End while
  6. Close reader1

thanks for your response

and how to insert variable inplace of po_detail_id in select statement

<insert..............................
SELECT po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit FROM Supp_Purchase_Indent_Dtl where requ_dtl_id=" & i>

please respond
Jun 7 '08 #5
CyberSoftHari
487 Expert 256MB
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO supp_purorder_dts_tbl(po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit) SELECT (" + intYourId + ") as po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit FROM Supp_Purchase_Indent_Dtl where requ_dtl_id=" & i
Note : the above code is not tested, Try some thing like this. Good luck
Jun 7 '08 #6
Expand|Select|Wrap|Line Numbers
  1. "INSERT INTO supp_purorder_dts_tbl(po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit) SELECT (" + intYourId + ") as po_detail_id, po_id, item_id, supp_qt_id, po_item_qty, po_item_rate, po_item_unit FROM Supp_Purchase_Indent_Dtl where requ_dtl_id=" & i
Note : the above code is not tested, Try some thing like this. Good luck

hello sir

i tried your code and i got error as
There is already an open DataReader associated with this Command which must be closed first.

at executenonquery i got this error


am putting my code below
c.con.Open()
c.cmd = New SqlCommand("select IsNull(Max(po_detail_id),0) from supp_purorder_dts_tbl", c.con)
piid = c.cmd.ExecuteScalar()
c.con.Close()

c.con.Open()
c.cmd = New SqlCommand("select * from Supp_Purchase_Indent_Dtl where job_no=" & hav, c.con)
c.dr = c.cmd.ExecuteReader()

While c.dr.Read()
piid = piid + 1

Dim i As Integer
i = c.dr("requ_dtl_id")

Dim a As String = ""
a = a & "INSERT INTO supp_purorder_dts_tbl(po_detail_id, po_id, item_id, supp_qt_id, "
a = a & " po_item_qty, po_item_rate, po_item_unit) SELECT (" & piid & ") as po_detail_id, po_id, item_id,"
a = a & " supp_qt_id, po_item_qty, po_item_rate, po_item_unit FROM Supp_Purchase_Indent_Dtl "
a = a & " where requ_dtl_id = " & i

c.cmd5 = New SqlCommand(a, c.con)
c.cmd5.ExecuteNonQuery()

End While
c.dr.Close()
c.con.Close()
Jun 10 '08 #7
CyberSoftHari
487 Expert 256MB
It is difficult to find the problem with too many code. Just post the line of code where is the error occurs (do not post all code) and explain more about your module flow.
Edit: follow the link above (#4), It will be helpful
Jun 10 '08 #8

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Jason Huang | last post by:
Hi, Is it possible to bind DataReader to a DataGrid in C# windows form? And how? And can we update data in a DataSet by using the DataReader? Thanks for help. Jason
20
by: Mark | last post by:
Hi all, quick question , a DataView is memory resident "view" of data in a data table therefore once populated you can close the connection to the database. Garbage collection can then be used to...
14
by: Bihn | last post by:
I was reading about datareader which is said to be slimmer & faster then dataset. Since the datareader have to go fetching the dat from the database every time it need it, the data it gets then...
3
by: tshad | last post by:
Is there a way to databind a datareader to 2 different dropdownlists? Something like: StoredSearches.DataSource=objCmd.ExecuteReader StoredSearches.DataValueField="SearchID"...
2
by: Patreek | last post by:
Hi, I'm writing my first real asp.net app at my job, and I'd like opinions please. In my classic ASP apps that I've written, I'd often have separate files for retreiving data and returning the...
15
by: Rob Nicholson | last post by:
I'm starting to worry a bit now. We're getting the above error when two users hit the same database/page on an ASP.NET application using ADO.NET, talking to a SQL 7 server. The error is perfectly...
3
by: bdwgarth | last post by:
I am trying to open a new web page for each item returned by the DataReader. I am using JavaScript to open each new window, and using a session variable to pass the DataReader Item value to the...
2
by: DaveS | last post by:
Hi! I am trying to create a DataReader in .Net 2003, retrieving data from an Access backend db. In the code below, when I put a breakpoint within the While...Read() loop, the datareader returns...
4
by: hazz | last post by:
The data access layer below returns, well, a mess as you can see on the last line of this posting. What is the best way to return customer objects via a datareader from the data layer into my view...
2
by: Andrew Robinson | last post by:
I am working on a data access layer using a pattern that I see more and more. Define a class that is a data container that is then added to a generic List<>. I am then using this List and support...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.