473,387 Members | 1,344 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,387 software developers and data experts.

dataset with streamwriter

hi,

i have a dataset and i want to select all the record belong to each empNo and write it to the filename start with that empNo.i can write the file but i don know whay it just write the last record belong to that empNo instead of write all records belong to each empNo. does anybody can help me out ?

here my code:
Expand|Select|Wrap|Line Numbers
  1.  objDataset = SQLHelperObj.ExecuteDataset(strTrngConn, CommandType.StoredProcedure, "Test")
  2.  
  3. Dim i As Integer
  4.  
  5. Dim var As String = ""
  6.  
  7. For i = 0 To objDataset.Tables(0).Rows.Count - 1
  8.         var = CStr(objDataset.Tables(0).Rows(i).Item("EmpNo"))
  9.         Dim sw As StreamWriter = New StreamWriter("C:\\Inetpub\\wwwroot\\Training\\Training\\Attachments\\" & CStr(objDataset.Tables(0).Rows(i).Item("EmpNo")) & ".txt")
  10.         sw.WriteLine(CStr(objDataset.Tables(0).Rows(i).Item("Doc")) & " " & CStr(objDataset.Tables(0).Rows(i).Item("Rev")) & " " & CStr(objDataset.Tables(0).Rows(i).Item("Title")))
  11.         sw.WriteLine(sw.NewLine)
  12.         sw.Close()
  13.  
  14.         Dim fileName As String = (CStr(objDataset.Tables(0).Rows(i).Item("EmpNo")) & ".txt")
  15.         Dim physicalPath As String = ("C:\\Inetpub\\wwwroot\\Training\\Training\\Attachments\\" + fileName)
  16.  
  17.         Me.Response.WriteFile(physicalPath)
  18.  
  19.         'strBody = strBody & vbTab & CStr(objRow("Doc")) & Space(10 - CStr(objRow("Doc")).Length) & CStr(objRow("Rev")) & Space(5 - CStr(objRow("Rev")).Length) & CStr(objRow("title")) & vbCrLf
  20.         'strBody = "Different EmpNo"
  21.         Next
  22.  
Here is my store proc:
Expand|Select|Wrap|Line Numbers
  1. CREATE proc Test
  2. as
  3. DECLARE @EmpNo INT, 
  4.         @Supervisor int, 
  5.         @Doc VARCHAR(30),
  6.         @Rev VARCHAR(10),
  7.         @Title varchar(255),
  8.         @InfoCardID varchar (18),
  9.         @Info_Card_ID varchar(255)
  10.  
  11. DECLARE @Result TABLE (EmpNo INT, Doc VARCHAR(50), Rev varchar(255), Title varchar(255))
  12.  
  13. DECLARE supervisor_cursor CURSOR 
  14. FOR
  15.    SELECT     tblEmployeeAlerts.EmpNo, tblEmployees.Supervisor 
  16.    FROM       tblEmployeeAlerts
  17.    INNER JOIN tblEmployees
  18.    ON         tblEmployeeAlerts.EmpNo = tblEmployees.EmpNo
  19.    WHERE      tblEmployees.Supervisor = 332
  20.  
  21. OPEN supervisor_cursor
  22. FETCH NEXT FROM supervisor_cursor INTO @EmpNo, @Supervisor
  23. PRINT 'OUTER LOOP START'
  24.  
  25. WHILE (@@FETCH_STATUS = 0)
  26. BEGIN
  27.     SET @Doc = ''
  28.     DECLARE curDetailList CURSOR 
  29.     FOR
  30.        SELECT distinct dbo.tblCurrentRev.tdc_doc_Num as doc, 
  31.                        dbo.tblCurrentRev.Rev as Rev, 
  32.                        MP_MPI.dbo.tdc_doc_infocard.title_nm as Title, 
  33.                        dbo.tblCurrentRev.InfoCardID, 
  34.                        dbo.tblTrainingRecord.info_card_id 
  35.        FROM            dbo.tblCurrentRev 
  36.        INNER JOIN      MP_MPI.dbo.tdc_doc_infocard 
  37.        ON              dbo.tblCurrentRev.InfoCardID = MP_MPI.dbo.tdc_doc_infocard.info_card_id
  38.        INNER JOIN      dbo.tblJobDocs 
  39.        ON              dbo.tblCurrentRev.tdc_doc_Num = dbo.tblJobDocs.tdc_Doc_Num 
  40.        INNER JOIN      dbo.tblAssignments 
  41.        ON              dbo.tblJobDocs.JobProfileID = dbo.tblAssignments.ProfileID 
  42.        LEFT OUTER JOIN dbo.tblTrainingRecord 
  43.        ON              dbo.tblAssignments.EmpNo = dbo.tblTrainingRecord.empNo 
  44.        AND             dbo.tblCurrentRev.InfoCardID = dbo.tblTrainingRecord.info_card_id  
  45.  
  46.        WHERE           dbo.tblAssignments.EmpNo = @EmpNo
  47.        AND             dbo.tblTrainingRecord.info_card_id IS NULL
  48.        ORDER BY        tblCurrentRev.tdc_doc_num  
  49.  
  50.     OPEN curDetailList
  51.     FETCH NEXT FROM curDetailList INTO @Doc, @Rev, @Title, @InfoCardID, @Info_Card_ID
  52.  
  53.     PRINT 'INNER LOOP START'
  54.     WHILE (@@FETCH_STATUS = 0)
  55.     BEGIN
  56.          INSERT INTO @Result VALUES (@EmpNo, @Doc, @Rev, @Title)
  57.          FETCH NEXT FROM curDetailList INTO @Doc, @Rev, @Title, @InfoCardID, @Info_Card_ID
  58.          PRINT 'INNER LOOP'
  59.     END
  60.     CLOSE curDetailList
  61.     DEALLOCATE curDetailList
  62.  
  63. FETCH NEXT FROM supervisor_cursor INTO @EmpNo, @Supervisor
  64.  
  65. PRINT 'OUTER LOOP'
  66. END
  67.  
  68. CLOSE supervisor_cursor
  69. DEALLOCATE supervisor_cursor
  70.  
  71.  
  72. -- Publish result
  73.  
  74. SELECT * FROM @Result
  75. return
  76.  
Oct 6 '08 #1
1 915
DrBunchman
979 Expert 512MB
Hi langthanh,

Welcome to Bytes.com! I hope you find the site useful.

You've posted your question in the ASP Forum which is for Classic ASP only - I've moved it for you but in future please post all ASP.NET questions in the .NET Forum.

Please don't forget to wrap your code in CODE tags - it makes your posts much easier to read - and please read the Posting Guidelines if you have not done so already.

Thanks and I hope somebody can help you with your problem.

Dr B
Oct 7 '08 #2

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

Similar topics

4
by: Deepa | last post by:
Hi I have a DataSet file (xml) which I need to convert it into a tab delimited file. I need to write a C# console application for doing the same. Can anyone help me out with the code to do it? I'd...
2
by: Keith Chadwick | last post by:
I have a merged dataset that contains xml read from SQL Server. I need to place the data into an XPathDocument. I can do the following: mydataset.writeXML("mydata.xml") dim xpdoc as new...
0
by: Marko Maehner | last post by:
Hi, I have a strange problem with my xml file. In the schema of this xml file I have set one column to autoincrement. When I enter the data in my xml file directly, the autoincrement-column gets...
2
by: Wayne Wengert | last post by:
I am attempting to generate an XML file based on the contents of a dataset which contains a parent-child relationship but when I create the output file all I get is the XML header as shown here: ...
11
by: scorpion53061 | last post by:
Well I had a way to write an array to an excel spreadsheet but on a huge time critical run it failed iwth the dreaded HRESULT: 0x800A03EC error. It worked fine when i sampled the data to go in but...
6
by: Steven Nagy | last post by:
HI, This all applies to a project in the compact framework (Pocket PC). I need to convert a dataset object into XML which I will then send out via TCP. In a standard app I would do this as...
4
by: Brian Parker | last post by:
Here's a snippet of code I have: ============================================== DataSet ds = new DataSet(); string strXMLFileName = Path.GetTempFileName(); StreamWriter sw = File.AppendText(...
3
by: darrel | last post by:
I'm grabbing an XML string from a database and trying to pass it into a dataset. I've read this article: http://www.aspfaqs.com/aspfaqs/ShowFAQ.asp?FAQID=213 and have tried to implement it as...
4
by: Brad | last post by:
I am trying to convert an XML Stream received from a web api call into a DataSet to use in the rest of the app. The issue I am running into is that it will not convert the stream to a dataset and...
0
by: langthanh | last post by:
hi i have two datasets , one will return all employees belong to supervisor, and the other one will select all the documents belong to the temployees and write it to the files that have the...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.