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

dataset not commiting data

I am currently using VS.NET 2005 to read in a text file into a sql server
database table. The code cycles through the file and using a .add with a
dataset seems to add all the rows just fine.
When the program finishes and I go do a query on the table it is empty. I
am new to using VS so I am wondering what I am missing. Below is the code I
use to load the test file. Any help would be greatly appreciated.

** Code Example
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(filen ame)
MyReader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim ai As Integer
Dim ls_array(1) As String
Dim maxfields As Integer = 0

If tablenm = "agCRT" Then
maxfields = 149
ReDim ls_array(149)
ElseIf tablenm = "agWRT" Then
maxfields = 71
ReDim ls_array(71)
End If
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentfield As String
Dim fieldnum As Integer = 0
ai = 0
For Each currentfield In currentRow
ls_array(ai) = currentfield
ai = ai + 1
If ai maxfields Then
ds.Tables(tablenm).Rows.Add(ls_array)
End If
Next
Catch ex As
Microsoft.VisualBasic.FileIO.MalformedLineExceptio n
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
End While
End Using
** End Code Example
Apr 30 '07 #1
2 1086

"skl" <sk*@discussions.microsoft.comwrote in message
news:D7**********************************@microsof t.com...
>I am currently using VS.NET 2005 to read in a text file into a sql server
database table. The code cycles through the file and using a .add with a
dataset seems to add all the rows just fine.
How do you know this?
When the program finishes and I go do a query on the table it is empty. I
am new to using VS so I am wondering what I am missing. Below is the code
I
use to load the test file. Any help would be greatly appreciated.

** Code Example
I myself think you need to put the TRY before the Using to cover all of the
code.
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(filen ame)
MyReader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim ai As Integer
Dim ls_array(1) As String
Dim maxfields As Integer = 0

If tablenm = "agCRT" Then
maxfields = 149
ReDim ls_array(149)
ElseIf tablenm = "agWRT" Then
maxfields = 71
ReDim ls_array(71)
End If
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentfield As String
Dim fieldnum As Integer = 0
ai = 0
For Each currentfield In currentRow
ls_array(ai) = currentfield
ai = ai + 1
If ai maxfields Then
ds.Tables(tablenm).Rows.Add(ls_array)
End If
Next


You may need to just Catch ex as Exception to catch everything that could be
happening.
Catch ex As
Microsoft.VisualBasic.FileIO.MalformedLineExceptio n
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
End While
End Using
** End Code Example
Apr 30 '07 #2
Hi skl,

I believe you're trying to read CSV file (^_^). I have written a
simple CSV parser which loads it into a DataTable. You can find it in
my blog. I hope it helps.

Regards,
Hardono Arifanto
-----------------------
visit my blog at http://sodeve.net
On May 1, 1:26 am, skl <s...@discussions.microsoft.comwrote:
I am currently using VS.NET 2005 to read in a text file into a sql server
database table. The code cycles through the file and using a .add with a
dataset seems to add all the rows just fine.
When the program finishes and I go do a query on the table it is empty. I
am new to using VS so I am wondering what I am missing. Below is the code I
use to load the test file. Any help would be greatly appreciated.

** Code Example
Using MyReader As New
Microsoft.VisualBasic.FileIO.TextFieldParser(filen ame)
MyReader.TextFieldType =
Microsoft.VisualBasic.FileIO.FieldType.Delimited
MyReader.SetDelimiters(",")
Dim currentRow As String()
Dim ai As Integer
Dim ls_array(1) As String
Dim maxfields As Integer = 0

If tablenm = "agCRT" Then
maxfields = 149
ReDim ls_array(149)
ElseIf tablenm = "agWRT" Then
maxfields = 71
ReDim ls_array(71)
End If
While Not MyReader.EndOfData
Try
currentRow = MyReader.ReadFields()
Dim currentfield As String
Dim fieldnum As Integer = 0
ai = 0
For Each currentfield In currentRow
ls_array(ai) = currentfield
ai = ai + 1
If ai maxfields Then
ds.Tables(tablenm).Rows.Add(ls_array)
End If
Next

Catch ex As
Microsoft.VisualBasic.FileIO.MalformedLineExceptio n
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
End While
End Using
** End Code Example

May 1 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Grant | last post by:
Hello, How come when I add a new row to my dataset table it shows up as changed (agencyData.Haschanges() = True) but when I delete a row the dataset thinks here are no...
0
by: guy | last post by:
I have and arraylist bound to a datagrid which on the whole works fine, however if i select a row as soon as I leave the grid i get "Error when commiting row to backing datastore" I cant seem to...
0
by: guy | last post by:
I have and arraylist bound to a datagrid which on the whole works fine, however if i select a row as soon as I leave the grid i get "Error when commiting row to backing datastore" I cant seem to...
1
Kermit
by: Kermit | last post by:
Hi! I have another problem. This time with AutoNumbers. I insert a new row to a dataset (ds.Tables.Rows). How can I get it's id (which is an autonumber) without commiting changes to the database?
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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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,...

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.