Data rows not commiting to database.

G

Guest

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(filename)
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.MalformedLineException
MsgBox("Line " & ex.Message & _
" is invalid. Skipping")
End Try
End While
End Using
** End Code Example
 
W

William \(Bill\) Vaughn

Ah, consider that a DataSet (a collection of DataTable objects) is simply an
in-memory cache of data rows. Unless you execute an INSERT statement
somewhere along the line the data remain in memory until the application
ends...

If you're trying to move rows to SQL Server, consider use of the SqlBulkCopy
class.

--
____________________________________
William (Bill) Vaughn
Author, Mentor, Consultant
Microsoft MVP
INETA Speaker
www.betav.com/blog/billva
www.betav.com
Please reply only to the newsgroup so that others can benefit.
This posting is provided "AS IS" with no warranties, and confers no rights.
__________________________________
Visit www.hitchhikerguides.net to get more information on my latest book:
Hitchhiker's Guide to Visual Studio and SQL Server (7th Edition)
and Hitchhiker's Guide to SQL Server 2005 Compact Edition (EBook)
 
S

Sudhakar

you must configure dataadapter selectcommand, insertcommand, updatecommand,
deletecommand
to update database from dataset. Just populating dataset and datatable won't
update database.

With Regards
sudhakar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Top