473,386 Members | 1,795 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.

CSV File to database.

Hi
I have the following text file

1120,011522169050,01,+0000001,031221,0005.95,2003, 8331308,20031222
9924,014305689050,01,+0000001,031221,0005.95,2003, 8331308,20031222
1883,012152869050,01,+0000001,031222,0005.95,2003, 8331308,20031223
1896,017202869050,01,+0000001,031221,0005.95,2003, 8331308,20031222
1896,072211119050,01,+0000001,031222,0005.95,2003, 8331308,20031223
1908,028502869050,01,+0000001,031221,0005.95,2003, 8331308,20031222

I am trying to send this file to a database on sql server. I have the following code. I get all the message boxes when I press the command button but no data is sent to the database. Any ideas
Dim strFileName As String = "pos.txt
Dim strFilePath As String = "C:\pos\
Dim ds As New DataSe

Tr
Dim f As System.IO.Fil
If f.Exists(strFilePath & strFileName) The
Dim ConStr As String =
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" &
strFilePath & ";Extended Properties=""Text;HDR=No;FMT=Delimited\""
Dim conn As New OleDb.OleDbConnection(ConStr
Dim da As New OleDb.OleDbDataAdapter("Select * from " &
strFileName, ConStr

da.Fill(ds, "TextFile"
MsgBox(ds.Tables("TextFile").Rows.Count

End I
Catch ex As Exceptio
MessageBox.Show(ex.ToString
End Tr

'DataGrid1.DataSource = ds.Tables(0) >>>>>>>>>>>>>>UP TO HERE WORKS FINE. IT SHOWS UP IN THE GRI

Dim adoStr As String = "Server=nysvrprod01\enterprise;Database=POS;Us er ID=sa;Password=0cram;Trusted_Connection=False

Dim adoConn As New SqlConnection(adoStr
Dim adoDA As New SqlDataAdapte
Dim adoCmdInst As New SqlComman
adoCmdInst.CommandText = "INSERT INTO Pos_Data_File (POS_Store_Number, POS_UPC_Number," &
" POS_Issue_Number, POS_Quantity_Sold, POS_Sale_Date, POS_Cover_Price, POS_Issue_Year," &
" POS_Vendor_Number, POS_Transaction_Date) VALUES (@Pos_Store_Number, @POS_UPC_Number," &
" @POS_Issue_Number, @POS_Quantity_Sold, @POS_Sale_Date, @POS_Cover_Price, @POS_Issue_Year," &
" @POS_Vendor_Number, @POS_Transaction_Date)

adoConn.Open(

adoCmdInst.Connection = (adoConn

adoCmdInst.Parameters.Add(New SqlParameter("@POS_Store_Number", SqlDbType.Char, 4, "POS_Store_Number")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_UPC_Number", SqlDbType.VarChar, 15, "POS_UPC_Number")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Issue_Number", SqlDbType.Char, 3, "POS_Issue_Number")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Quantity_Sold", SqlDbType.VarChar, 10, "POS_Quantity_Sold")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Sale_Date", SqlDbType.NChar, 8, "POS_Sale_Date")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Cover_Price", SqlDbType.NChar, 10, "POS_Cover_Price")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Issue_Year", SqlDbType.Char, 4, "POS_Issue_Year")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Vendor_Number", SqlDbType.NChar, 9, "POS_Vendor_Number")
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Transaction_Date", SqlDbType.NChar, 8, "POS_Transaction_Date")
adoDA.InsertCommand = adoCmdIns

adoDA.Update(ds.Tables(0)

adoConn.Close(

MsgBox("Done")
Nov 22 '05 #1
3 1486
Chris:

Right before you call adoDA.Update, insert this line of code:
Debug.Assert(ds.HasChanges) . If you don't see a big ugly assertion box,
then the rowstate of those records isn't being marked as Inserted which
appears to be the problem.
"Chris" <de*****@yahoo.com> wrote in message
news:95**********************************@microsof t.com...
Hi,
I have the following text file:

1120,011522169050,01,+0000001,031221,0005.95,2003, 8331308,20031222
9924,014305689050,01,+0000001,031221,0005.95,2003, 8331308,20031222
1883,012152869050,01,+0000001,031222,0005.95,2003, 8331308,20031223
1896,017202869050,01,+0000001,031221,0005.95,2003, 8331308,20031222
1896,072211119050,01,+0000001,031222,0005.95,2003, 8331308,20031223
1908,028502869050,01,+0000001,031221,0005.95,2003, 8331308,20031222

I am trying to send this file to a database on sql server. I have the following code. I get all the message boxes when I press the command button
but no data is sent to the database. Any ideas.
Dim strFileName As String = "pos.txt"
Dim strFilePath As String = "C:\pos\"
Dim ds As New DataSet
Try
Dim f As System.IO.File
If f.Exists(strFilePath & strFileName) Then
Dim ConStr As String = _
"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _
strFilePath & ";Extended Properties=""Text;HDR=No;FMT=Delimited\""" Dim conn As New OleDb.OleDbConnection(ConStr)
Dim da As New OleDb.OleDbDataAdapter("Select * from " & _
strFileName, ConStr)

da.Fill(ds, "TextFile")
MsgBox(ds.Tables("TextFile").Rows.Count)

End If
Catch ex As Exception
MessageBox.Show(ex.ToString)
End Try

'DataGrid1.DataSource = ds.Tables(0) >>>>>>>>>>>>>>UP TO HERE WORKS FINE. IT SHOWS UP IN THE GRID

Dim adoStr As String = "Server=nysvrprod01\enterprise;Database=POS;Us er
ID=sa;Password=0cram;Trusted_Connection=False"

Dim adoConn As New SqlConnection(adoStr)
Dim adoDA As New SqlDataAdapter
Dim adoCmdInst As New SqlCommand


adoCmdInst.CommandText = "INSERT INTO Pos_Data_File (POS_Store_Number, POS_UPC_Number," & _ " POS_Issue_Number, POS_Quantity_Sold, POS_Sale_Date, POS_Cover_Price, POS_Issue_Year," & _ " POS_Vendor_Number, POS_Transaction_Date) VALUES (@Pos_Store_Number, @POS_UPC_Number," & _ " @POS_Issue_Number, @POS_Quantity_Sold, @POS_Sale_Date, @POS_Cover_Price, @POS_Issue_Year," & _ " @POS_Vendor_Number, @POS_Transaction_Date)"
adoConn.Open()

adoCmdInst.Connection = (adoConn)
adoCmdInst.Parameters.Add(New SqlParameter("@POS_Store_Number", SqlDbType.Char, 4, "POS_Store_Number")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_UPC_Number", SqlDbType.VarChar, 15, "POS_UPC_Number")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Issue_Number", SqlDbType.Char, 3, "POS_Issue_Number")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Quantity_Sold", SqlDbType.VarChar, 10, "POS_Quantity_Sold")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Sale_Date", SqlDbType.NChar, 8, "POS_Sale_Date")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Cover_Price", SqlDbType.NChar, 10, "POS_Cover_Price")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Issue_Year", SqlDbType.Char, 4, "POS_Issue_Year")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Vendor_Number", SqlDbType.NChar, 9, "POS_Vendor_Number")) adoCmdInst.Parameters.Add(New SqlParameter("@POS_Transaction_Date", SqlDbType.NChar, 8,
"POS_Transaction_Date"))

adoDA.InsertCommand = adoCmdInst
adoDA.Update(ds.Tables(0))
adoConn.Close()
MsgBox("Done")

Nov 22 '05 #2
Hi
Thanks for responding. I did see a big message box. Any ideas

Thanks
Nov 22 '05 #3
Cor
Hi Chris,

I'm am not with Bill on this one, I gave you a complete sample how to do it.
Did you look at the long help I did give you? In this is also why this will
not work.

After the part from the first sample (that is untill where your problem
works) I see nothing back from the rest I did write.

Cor
Nov 22 '05 #4

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

Similar topics

0
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: Fran Tirimo | last post by:
I am developing a small website using ASP scripts to format data retrieved from an Access database. It will run on a Windows 2003 server supporting FrontPage extensions 2002 hosted by the company...
2
by: KULJEET | last post by:
control file not created at time of installtion of oracle database now how we can create it see alert file Dump file e:\ORacle\admin\new\bdump\newALRT.LOG Tue Sep 09 10:45:53 2003 ORACLE...
6
by: varlagas | last post by:
We disabled the antivirus software but the problem persists. Any clues? Many thanks in advance! Panagiotis Varlagas ======================================================================= ...
9
by: John | last post by:
Hi All, I have encountered a problem with the ldb file of a database. When making changes to the backend databases I need exclusive access to make changes. I usually do this at night when all...
4
by: Jamey Shuemaker | last post by:
A2k2 with user-level security and all preventive measures, vis a vis, Security FAQ enabled or enacted. I've got three DBs, which due to size constraints can't, or rather, probably shouldn't be...
5
by: B. Williams | last post by:
I need some assistance with random access file processing. I have a function that I would like to change from sequential file processing to random access. Thanks in advance. void...
7
by: ConfusedAlot | last post by:
This is my code for a database, whenever i save the database to the file 'database.txt' and display the results i get this; name - (correct, is what i put in) pin - 3435973836 slew rate -...
12
by: Darrel | last post by:
I'm still having a hell of a time figuring out this whole SQL Express set up. I finally discovered why I couldn't run the aspnet_regsql...my local sql server wasn't running. I turned that on,...
10
by: Redhairs | last post by:
In a web farm environment, how to store the user uploading files for future access? Store them in db, local file system or centralized file server? If trying to storing the file in local file...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
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
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.