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
- <script runat="server">
- Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs)
- If (IsPostBack) Then
- Grid1.Visible = True
- Else
- Grid1.Visible = False
- End If
- End Sub
- Sub UploadButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- 'Save the uploaded file to an "Uploads" directory
- ' that already exists in the file system of the
- ' currently executing ASP.NET application.
- ' Creating an "Uploads" directory isolates uploaded
- ' files in a separate directory. This helps prevent
- ' users from overwriting existing application files by
- ' uploading files with names like "Web.config".
- Dim saveDir As String = "\Data\"
- ' Get the physical file system path for the currently
- ' executing application.
- Dim appPath As String = Request.PhysicalApplicationPath
- ' Before attempting to save the file, verify
- ' that the FileUpload control contains a file.
- If (FileUpload1.HasFile) Then
- Dim savePath As String = appPath + saveDir + FileUpload1.FileName
- ' Call the SaveAs method to save the
- ' uploaded file to the specified path.
- ' This example does not perform all
- ' the necessary error checking.
- ' If a file with the same name
- ' already exists in the specified path,
- ' the uploaded file overwrites it.
- FileUpload1.SaveAs(savePath)
- ' Notify the user that the file was uploaded successfully.
- UploadStatusLabel.Text = "Your file was uploaded successfully."
- Else
- ' Notify the user that a file was not uploaded.
- UploadStatusLabel.Text = "You did not specify a file to upload."
- End If
- End Sub
- Sub DisplayButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
- Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=C:\inetpub\wwwroot\MerlinLocalPostOfficeApp\Data;Extended Properties=""text;HDR=NO;FMT=Delimited"""
- Dim objConn As New OleDbConnection(sConnectionString)
- objConn.Open()
- Dim objCmdSelect As New OleDbCommand("SELECT * FROM csv.txt", objConn)
- Dim objAdapter1 As New OleDbDataAdapter()
- objAdapter1.SelectCommand = objCmdSelect
- Dim objDataset1 As New DataSet()
- objAdapter1.Fill(objDataset1, "csv.txt")
- Grid1.DataSource = objDataset1.Tables(0).DefaultView
- Grid1.DataBind()
- objConn.Close()
- End Sub
- </script>
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