.Net Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - More.Net Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Be the architects of evolution and help create the mobile internet future. It’s your move---enter to win here!
  #1  
Old May 9th, 2008, 02:23 PM
randallj2877 randallj2877 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jul 2005
Posts: 107 randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level)randallj2877 User rank is Sergeant (500 - 2000 Reputation Level) 
Time spent in forums: 1 Day 7 h 21 m 44 sec
Reputation Power: 9
Question DataView has one less "row" than DataTable?

I have the following code:

PHP Code:
 1            private void UpdateDatabase(string csvFilePathstring delimiterNamestring tableName)
2            {
3                TableDataAccess dataAccess = new TableDataAccess();
4                DataTable dataTable dataAccess.GetTableInfo("SELECT * FROM " tableNametableNamenull);
5                DataView dataView dataTable.DefaultView;
6    
7                string fileLine
;
8                IList<stringlines = new List<string>();
9                IList<stringparameters = new List<string>();
10               string delimiter = (delimiterName == "Comma") ? "," : @"\t";
11               int columnCount 0;
12   
13               
// Open file
14               if (File.Exists(@csvFilePath))
15               {
16                   // Open file
17                   FileInfo csvFile = new FileInfo(@csvFilePath);
18   
19                   
// Create resource stream
20                   StreamReader reader csvFile.OpenText();
21   
22                   
// traverse each line of file      
23                   while (!reader.EndOfStream)
24                   {
25                       fileLine reader.ReadLine().Trim();
26                       if (!String.IsNullOrEmpty(fileLine) && !lines.Contains(fileLine))
27                       {
28                           string[] columnData Regex.Split(fileLinedelimiter);
29                           DataRowView drv dataView.AddNew();
30                           columnCount columnData.Length;
31   
32                           
for (int i 0columnCounti++)
33                           {
34                               drv[i] = columnData[i];
35                           }
36   
37                           lines
.Add(fileLine);
38                       }
39                   }
40   
41                   
// Close stream
42                   reader.Close();
43   
44                   
// Construct INSERT query
45                   StringBuilder sql = new StringBuilder();
46                   sql.Append("INSERT INTO ");
47                   sql.Append(tableName);
48                   sql.Append(" VALUES (");
49                   for (int i 0columnCounti++)
50                   {
51                       parameters.Add("Value" i);
52                       sql.Append("@Value" i);
53   
54                       
if (!= columnCount 1)
55                       {
56                           sql.Append(",");
57                       }
58                       else
59                       {
60                           sql.Append(")");
61                       }
62                   }
63   
64                   dataAccess
.UpdateTableInfo(sql.ToString(), tableNamedataTableparameters);
65               }
66           


I'm basically taking the contents of a delimited text file (i.e., .csv file or tab-delimited text file) and uploading it to a database table. The data access layer is hidden here, but you don;t need to see it (because the problem is not in there).

For some crazy reason "dataTable" has one less row than "dataView" (even though DataViews don't technically have rows?), immediately before the dataAccess.UpdateTableInfo() method is executed (verified this in the debugger). The data count should be the same, but it isn't. As a result, my updated database table (getting its data from "dataTable" via method dataAccess.UpdateTableInfo() ) is missing the very last line of data in the delimited text file.

I can only presume that the last DataRowView created in my while loop (used to iterate through the lines of my delimited text file), while added to the DataView, is never "committed" to the accompanying DataTable. The final value of "fileLine" in that loop IS the value of the last line in the text file (verified in debugger).

So why is the the last line of the file, contained in the final, newly-added DataRowView in my DataView, never added to the corresponding DataTable. Is there a way to "commit" changes to the DataTable before I send it to my data access logic, to be subsequently added to my database table?

What exactly is going on here? ...Thanks.
__________________
__________________
Regards, R.J.

Media Moguls
Cleveland, Ohio Web Site Design and Application Development

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - More.Net Development > DataView has one less "row" than DataTable?


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 3 hosted by Hostway