Connecting Tech Pros Worldwide Help | Site Map

dataset with streamwriter

Newbie
 
Join Date: Oct 2008
Posts: 2
#1: Oct 6 '08
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.  
DrBunchman's Avatar
Moderator
 
Join Date: Jan 2008
Location: Winchester, UK
Posts: 930
#2: Oct 7 '08

re: dataset with streamwriter


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
Reply