473,387 Members | 3,810 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,387 software developers and data experts.

Urgent help Please

Hi Guys

i write a thread before asking for help with reading an uploaded csv file,

i have my code, it reads the csv file and currently displays it in a datagrid but what i actually want is to take the read information and import it into my sql express db.

Heres the code

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.         ' that already exists in the file system of the 
  12.         ' currently executing ASP.NET application.  
  13.         ' Creating an "Uploads" directory isolates uploaded 
  14.         ' files in a separate directory. This helps prevent
  15.         ' users from overwriting existing application files by
  16.         ' uploading files with names like "Web.config".
  17.         Dim saveDir As String = "\Data\"
  18.  
  19.         ' Get the physical file system path for the currently
  20.         ' executing application.
  21.         Dim appPath As String = Request.PhysicalApplicationPath
  22.  
  23.         ' Before attempting to save the file, verify
  24.         ' that the FileUpload control contains a file.
  25.         If (FileUpload1.HasFile) Then
  26.             Dim savePath As String = appPath + saveDir + FileUpload1.FileName
  27.  
  28.             ' Call the SaveAs method to save the 
  29.             ' uploaded file to the specified path.
  30.             ' This example does not perform all
  31.             ' the necessary error checking.               
  32.             ' If a file with the same name
  33.             ' already exists in the specified path,  
  34.             ' the uploaded file overwrites it.
  35.             FileUpload1.SaveAs(savePath)
  36.  
  37.             ' Notify the user that the file was uploaded successfully.
  38.             UploadStatusLabel.Text = "Your file was uploaded successfully."
  39.  
  40.         Else
  41.             ' Notify the user that a file was not uploaded.
  42.             UploadStatusLabel.Text = "You did not specify a file to upload."
  43.         End If
  44.  
  45.     End Sub
  46.  
  47.     Sub DisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
  48.         Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Data;Extended Properties=""text;HDR=NO;FMT=Delimited"""
  49.         Dim objConn As New OleDbConnection(sConnectionString)
  50.         objConn.Open()
  51.         Dim objCmdSelect As New OleDbCommand("SELECT * FROM csv.txt", objConn)
  52.         Dim objAdapter1 As New OleDbDataAdapter()
  53.         objAdapter1.SelectCommand = objCmdSelect
  54.          Dim objDataset1 As New DataSet()
  55.         objAdapter1.Fill(objDataset1, "csv.txt")
  56.         Grid1.DataSource = objDataset1.Tables(0).DefaultView
  57.         Grid1.DataBind()
  58.         objConn.Close()
  59.     End Sub
  60.  
  61.  
  62.   </script>
  63.  
My csv file does not have headers so the default value is F1, F2, F3 F4, F5,F6, F7, my database has 7 columns, ID,AddressLine1,AddressLine2,AddressLine3,AddressL ine4,AddressLine5,AddressLine6,Postcode

I need to know how to import the information direct into the db rather than displaying it on the page, ive tried but im really new to this and cant get it to work. I cant use DTS or bulk insert as the server this will go on doesnt have sql on it, the db is an MDF file so is transportable with the app.

Thanks for your help
Feb 25 '07 #1
1 1177
First, I'm thinking that having an .mdf without an instance of SQL Server to attach to is fairly useless. Check the following usenet post for support Google Usenet Posting

So, thats rough and might need rethinking.

Second, to not display we just don't bind it to a control that renders to the page. Instead, we can read the .csv into a dataset, get a dataset of the table we pushing to and get on with life.

Store procedure would be good for this though. Cheers.
Feb 25 '07 #2

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

Similar topics

2
by: learner | last post by:
Hi, In a page, i have many links. I have some functions in a global file which is included in all linked pages. I want to have a reference to a window which is to be opened on clicking one link...
2
by: Dimitri | last post by:
PLEASE HELP,I HAVE A DATABSE WITH MULTIPLE RECORDS AS OUTLINED BELOW EMP NO LEVEL NEXTINCREASE WAGETYPE UNIT 1000 1 0 1000 1000 1 0 1002 ...
28
by: Tamir Khason | last post by:
Follwing the struct: public struct TpSomeMsgRep { public uint SomeId;
0
by: Charles Dido | last post by:
Sir, I am MR.CHARLES ALAMIEYESEIGHA. I am the son of GOVONOUR of BAYELSA STATE IN NIGERIA.Some months ago, this YEAR, my father was arrested in LONDON by the LONDON METHROPOLITAN POLICE for...
17
by: Saps | last post by:
Hi all. Can anyone help me here. I have loads of .sql files and i need a way to call these from my asp page so the user can run them from the browser. Meaning i have a page with a list of all...
3
by: N. Spiker | last post by:
I am attempting to receive a single TCP packet with some text ending with carriage return and line feed characters. When the text is send and the packet has the urgent flag set, the text read from...
4
by: Adrian Parker | last post by:
We've suddenly started getting a problem with a call to clear the contents of a DataTable. This is on a live customer site that's been working fine until yesterday. As far as we know they've not...
5
by: igotyourdotnet | last post by:
I'm creating a web service this is going to return an arraylist of items. When I try and run it Im' getting the following error message: System.InvalidOperationException: There was an error...
4
by: ashasivan | last post by:
Hi, Please help me as soon as possible for the following problem. It is very very urgent. I have an XML file as follows: <?xml version="1.0" standalone="yes"?> <Employee> <em...
1
by: psantosh12 | last post by:
Hello Frnds Please need help to resolve error.......... it is very very urgent........ The error is Runtime Error Description: An application error occurred on the server. The current custom...
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
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
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
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
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.