473,725 Members | 2,053 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Help with Csv to SQL db upload

19 New Member
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,A ddressLine3,Add ressL ine4,AddressLin e5,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 1057

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

Similar topics

4
2935
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 upload files, like this: copy ($myfile, $uploadfolder . "/" . $myfile_name); Everything works fine, it can process large files and everything, but i need to make sure that people only upload pictures, so i change
2
3929
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 them a caption, storing the caption and filename in a text file. It's a bit buggy when removing the photos and captions from the file, and also in displaying them on the delete page. you can see it in action at www.4am.com.au/gallery/upload.php...
2
2265
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 <?php if (!isset($_POST)) {
8
1617
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 installed .net then i repaired IIS. Again i installed FrameWork 1.1 I dont know what was the problem.
3
1578
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 this all happens at same time Works great
1
2588
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 ....... can somebody help me <%@ Language=VBScript %> <%Option Explicit%>
7
3189
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" name="file_1" size=46 /><input type=submit /> so, after adding a few files, the input fields look like this:
3
2198
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 both on the file system and in a mySql database. 90% of the time it works just fine. But for some reason, with some photos, it doesn't work. The image never shows up on the filesystem and there is no entry in the database. I feel it's a problem...
3
2638
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 for up to 20mbs though so I was hoping that someone would be able to change this code to ASP(I am not very good at either php or asp). I think that should be pretty easy <?php if (is_uploaded_file($_FILES)) {
0
1177
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 the login form 4 get the _crumb and Sig values
0
8888
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9401
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9174
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6702
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6011
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4782
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3221
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2634
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2157
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.