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

Help with Csv to SQL db upload

I have a web app ive built in Visual studio 2005 VB.net and uses sql server. However the Server this will be applied on doesnt have sql server so will utilise an mdf database. I am very new to all this so please be patient with me.

The app searches postoffices via street address, post code or town and works fine, my problem is that i need to be able to upload csv of the post office information into my db, i cant use bulk insert or dts so need to do this through an aspx page.

My code so far saves a csv file to a directory and then opens the file and reads it, currently it then displayed this to a datagrid but i simply want to insert the read information into my db, can someone please look at my code and help me achieve this as im very lost with it all and have become very confused about how to get the information in there. Ive search many sites and msdn and cant find anything that meets my needs, your help would be greatly appreciated

My csv file does not have headers, my database has 8 columns, ID,AddressLine1,AddressLine2,AddressLine3,AddressL ine4,AddressLine5,AddressLine6,Postcode. The ID is generated each time a new line is inserted but not sure how to achieve this either, please see the code below.

Expand|Select|Wrap|Line Numbers
  1. <script runat="server">    
  2.     Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
  3.         If (IsPostBack) Then
  4.             Grid1.Visible = True
  5.         Else
  6.             Grid1.Visible = False
  7.         End If
  8.     End Sub
  9.     Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  10.         'Save the uploaded file to an "Uploads" directory
  11.         Dim saveDir As String = "\Data\"
  12.  
  13.         ' Get the physical file system path for the currently
  14.         ' executing application.
  15.         Dim appPath As String = Request.PhysicalApplicationPath
  16.  
  17.         ' Before attempting to save the file, verify
  18.         ' that the FileUpload control contains a file.
  19.         If (FileUpload1.HasFile) Then
  20.             Dim savePath As String = appPath + saveDir + FileUpload1.FileName
  21.  
  22.             ' Call the SaveAs method to save the 
  23.             ' uploaded file to the specified path.
  24.             FileUpload1.SaveAs(savePath)
  25.  
  26.             ' Notify the user that the file was uploaded successfully.
  27.             UploadStatusLabel.Text = "Your file was uploaded successfully."
  28.  
  29.         Else
  30.             ' Notify the user that a file was not uploaded.
  31.             UploadStatusLabel.Text = "You did not specify a file to upload."
  32.         End If
  33.  
  34.     End Sub
  35.  
  36.     Sub DisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  37.         Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\inetpub\wwwroot\MerlinLocalPostOfficeApp  \Data;Extended Properties=""text;HDR=NO;FMT=Delimited"""
  38.         Dim objConn As New OleDbConnection(sConnectionString)
  39.         objConn.Open()
  40.         Dim objCmdSelect As New OleDbCommand("SELECT * FROM csv.txt", objConn)
  41.         Dim objAdapter1 As New OleDbDataAdapter()
  42.         objAdapter1.SelectCommand = objCmdSelect
  43.          Dim objDataset1 As New DataSet()
  44.         objAdapter1.Fill(objDataset1, "csv.txt")
  45.         Grid1.DataSource = objDataset1.Tables(0).DefaultView
  46.         Grid1.DataBind()
  47.         objConn.Close()
  48.     End Sub
  49.  
  50.  
  51.   </script>
  52.  
Feb 27 '07 #1
0 1017

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: Tihon | last post by:
Hello! I again need your help, just can't understand whats going on. Got this upload pictures form and it's having problem handling large files (~1.5 - 2 MB). Everything works fine if i just...
2
by: matt | last post by:
I have compiled some code, some written by me, some compiled from various sources online, and basically i've got a very simple flat file photo gallery. An upload form, to upload the photos and give...
2
by: Dynamo | last post by:
Hi I am using a form to upload an image from my hard drive to my server but there is something amiss cause I am continually getting an error message "FTP upload has failed" This is my code ...
8
by: Murali Inguva | last post by:
I am getting the following error. I Created a Web Project then added upload.aspx Then I got this error. I keep aspx controls i am geeting this error. I have xp pro with IIS Installed then i...
3
by: Chris Calzaretta | last post by:
Hello Working with system.threading.thread Ok I have an windows user control. It has 3 thread on it thread 1 uploaded files types a thread 2 upload files types b thread 3 upload files types c...
1
by: Rizwan | last post by:
I am writing this code for file upload in asp 3.0 on my webpage........ It is working on local system but when i want to upload an image on my website from client machine it is not working ..........
7
by: pbd22 | last post by:
hi. i am having probs understanding how to grab a file being uploaded from a remote client. i am using hidden input fields for upload such as: <input id="my_file_element" type="file"...
3
by: Milagro | last post by:
Hello Everyone, I'm trying to debug someone elses php code. I'm actually a Perl programmer, with OO experience, but not in php. The code is supposed to upload a photo from a form and save it...
3
by: Rabel | last post by:
I am having trouble with our server host they are saying that the php upload limit is 20 mbs but using the code below with my flash file I can only get it to do 8mbs. I know that asp is allowing...
0
by: eliana | last post by:
Hello I'm trying to write some code to upload video to YahooVideo! I'm using cUrl.. Basically I go trough the following steps: 1 call the login page 2 get challenge and user values 3 send...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

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.