Reading - Parsing And Posting Data From A .csv File Into A SQL Database

Jul 13, 2010

I have the following data that basically I only need a few bits of information from:

Resource:X - Y;Z - Å;Type:(all) From Date:
07/12/2010 - To Date 07/12/2010 Sort
by:Time Include Referring
source/physician:No Footer:Default
Criteria:None
","Appointments","X,
Y","ZAssociates","Monday, July 12,
2010","Time","Patient Name","Patient
ID","Appt. Type","Ref. Source/
Physician","Phone","Type","DOB
","Z, X","Y","7/12/2010
12:00:00AM","Time","Patient
Name","Patient ID","Appt.
Type","Phone","Type","DOB "," 7:30
[snip]

The only things I need from this are:

Patients Name
Drs Name
Patients Phone Number
Appt Time
Appt Date

and the rest of the information I can discard. A customer uploads this as a .csv file (even though it really isn't as you can see) and I'd like to parse the needed information and post that to my SQL database and discard the rest. I think I can do this with a dataset but I've never built that before. The fields from the customer will always be the same and the fields I will need will always be the same. Also, the date time has to be in the format of yyyy/mm/dd:hhmm and the phone number always has to have 512 as a prefix. Here is the code I currently have for my site:

Imports System.IO
Imports System.Data
Imports System.Data.SqlClient
Partial Class _Default
Inherits System.Web.UI.Page
Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
End Sub
Protected Sub Submit1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Dim SaveLocation = "\xxxWEB3wwwrootWebfile1RemindersDoug_Ancildoug.csv"
If UploadFile(SaveLocation) Then
'the file was uploaded: now try saving it to the database
SaveToDatabase(SaveLocation)
End If
End Sub
Private Function UploadFile(ByVal SavePath As String) As Boolean
Dim fileWasUploaded As Boolean = False 'indicates whether or not the file was uploaded
'Checking if the file upload control contains a file
If Not File1.PostedFile Is Nothing And File1.PostedFile.ContentLength > 0 Then
Try
'checking if it was .txt file BEFORE UPLOADING IT!
'You used to upload it first...but the file could be a virus
If File1.FileName = ("doug.csv") = False Then
'The file is not the expected type...do not upload it
'just post the validation message
message.Text = "Sorry, thats not the correct file."
message2.Text = "Please locate and upload 'doug.csv'"
Else
'The file is a .txt file
'checking to see if the file exists already
'If it does exist Deleting the existing one so that the new one can be created
If IO.File.Exists(SavePath) Then
IO.File.Delete(SavePath)
End If
'Now upload the file (save it to your server)
File1.PostedFile.SaveAs(SavePath)
'After saving it check to see if it exists
If File.Exists(SavePath) Then
'Upload was sucessful
message.Text = "Thank you for your submission."
fileWasUploaded = True
Else
'the file was not saved
message.Text = "Unable to save the file."
End If
End If
Catch Exc As Exception
'We encountered a problem
message.Text = "Your file was not in the correct format. Please contact Customer Service at xxxx-xxxx-xxxx."
End Try
Else
'No file was selected for uploading
message.Text = "Please select a file to upload."
End If
Return fileWasUploaded
End Function
Private Sub SaveToDatabase(ByVal SavePath As String)
Try
Dim sqlQueryText As String = _
"BULK INSERT dialerresults " + _
"FROM '" & SavePath & "' " + _
"WITH ( FIELDTERMINATOR = ',' , ROWTERMINATOR = '
' )"
' and bulk import the data:
'If ConfigurationManager.ConnectionStrings("Dialerresults") IsNot Nothing Then
'Dim connection As String = ConfigurationManager.ConnectionStrings("Dialerresults").ConnectionString
Dim connection As String = "data source=10.2.1.40;initial catalog=IVRDialer;uid=xxxx;password=xxxxx;"
Using con As New SqlConnection(connection)
con.Open()
' execute the bulk import
Using cmd As New SqlCommand(sqlQueryText, con)
cmd.ExecuteNonQuery()
End Using
End Using
'Else
'message.Text="ConfigurationManager.ConnectionStrings('Dialerresults') is Nothing!"
'End If
Catch ex As Exception
message.Text = "Your file was not in the correct format. Please contact Customer Service at xxxxxxx."
End Try
End Sub
End Class

View 1 Replies


Similar Messages:

Web Forms :: Reading And Posting A .csv File Into A SQL Database

Jul 13, 2010

I have the following data that basically I only need a few bits of information from: The only things I need from this are:

Patients Name
Drs Name
Patients Phone Number
Appt Time
Appt Date

and the rest of the information I can discard. A customer uploads this as a .csv file (even though it really isn't as you can see) and I'd like to parse the needed information and post that to my SQL database and discard the rest. I think I can do this with a dataset but I've never built that before. The fields from the customer will always be the same and the fields I will need will always be the same. Also, the date time has to be in the format of yyyy/mm/dd:hhmm and the phone number always has to have 512 as a prefix. Here is the code I currently have for my site:

[Code]....

View 30 Replies

Reading A .csv File And Outputting Data To Database?

Jan 25, 2011

I have a csv file with 5 columns. I need to read this file using c# and have to write the contents to the table in database which has 5 columns to it.

if anyone know the code or steps to do this.

View 8 Replies

SQL Server :: Reading Data From .CSV File Into Sql Database

Jul 15, 2010

I urgently need to find a way of reading data from a .CSV or .xls(Excel) file into an sql database so that I can use it in my asp.net 2.0 application.

View 4 Replies

Databases :: Upload Ms Word File And Store It Into Database Then Reading The File?

Jan 12, 2011

i like to create a web application,in that i need to get the resumes from the user,then i need to publish that resume to the manager in date wise..

View 5 Replies

Reading File And Store In Database?

Mar 9, 2010

I m reading a text file. After reading all the lines, I want to insert those records into respective fields in database.

So how to store the 1 or 2 or 3 or 4 or 5 lines of records until I read the last record.?

[code]....

first 9 number is emp id, next is name and next is salary.

While I m reading, I can store only last record. How to store all the records in a array to store in the database after reading all the lines.

View 12 Replies

Web Forms :: Create Text File While Reading From Database?

Oct 1, 2010

How to create Text file while reading from database?

DataBase Table has 10 records in it
ID Name Age
1 Jon 18
2 Martin 20
..
..
10 Andy 30

I want create a text file like this

ID: 1
Name: Jon
Age: 18
-----------------
ID: 2
Name: Martin
Age: 20
-----------------
ID: 10
Name: Andy
Age: 30

View 4 Replies

Reading A File Into Memory And Then Reading It One Line At A Time?

Mar 7, 2011

I know this is probably a pretty easy thing to do and it is if I can upload the file and store it onto the hard drive of the server. What I need to do is read the text file into memory and then parse through it one line at a time. Anyone have any code that demonstrates that?

View 8 Replies

SQL Server :: Parsing An Array Read From An MS Database/'System.Data.SqlClient.SqlDataAdapter' Does Not Contain A Definition For 'Rows'...

Mar 23, 2011

I am getting this error:

CS1061: 'System.Data.SqlClient.SqlDataAdapter' does not contain a definition for 'Rows' and no extension method 'Rows' accepting a first argument of type 'System.Data.SqlClient.SqlDataAdapter' could be found.

Here is my code, what am I doing wrong?:

[Code]....

View 4 Replies

Web Forms :: Double Posting - Adding More Data To The Database

Nov 16, 2010

I have deveopmed i web site in ASP.NET and C# using Visual Studio 2008. I have a problem with performing button events twice. A user has a web page open. He click on a button (Save) and data is added to the database. He then presses F5 to update the page, and the button event is fired again adding more data to the database that should no be added. My question is how can I avoid this scenario?

View 3 Replies

WCF / ASMX :: Reading Data From Database Using Web Service

Apr 25, 2010

I have a requirement in which i have a database table which has 4 columns Id,Name,position,city.....now i have a form in which the user will be filling in the id and then the other three columns should auto populate ....now i want a web service which will make a data connection and get the Id from the form and then query the database and get the other three columns..i am pretty new to web services ..can somebody give me some heads up on how to achieve this...let me know if i have to provide more details.

View 8 Replies

Databases :: Reading Excel Data To SQL Database

Sep 23, 2010

Using C# to develop an application.I need to upload data ( which is in excel) to a sql table.

[Code]....

View 1 Replies

Parsing Url From Xml File?

Aug 18, 2010

I have a xml file having the tags like

<link>
<linkto>[URL]/broadcasts/index.cfm?fuseaction=usrbrd&broadcasterid=57468</linkto>
<image>report_button</image>
<alt>Report a Problem</alt>
<target></target>
</link>
<linkto> tag have the url. But because of the "&" symbol in the url thats completely crashing the page. I tried using like amp; next to the & symbol but this doesn't give the correct url.

View 3 Replies

Textfiles - Reading Data From Flat File

Jan 27, 2011

i have flat files in some direcotry. each flat file contains around 60,000 rows of data. earlier we were using excel sheets to upload data. but now the challenge is it is taking more time to upload data into DB tables. which is the best way to upload such a huge data into db tables. can we use SSIS for uploading data. if so, how can we achieve that.

View 1 Replies

C# - Encoding While Parsing XML File

Dec 11, 2010

I'm developing a small ASP.NET Mvc project in Mono 2.4, Ubuntu 10.10. There is an array of objects, each one of them corresponds to a certain xml file. Reading of the xmls is performed with XmlTextReader. That does not work because xml files have rare "cp866nav" encoding, which is not supported by XmlTextReader ("System.ArgumentException: Encoding name 'cp866nav' not supported"). But it works fine if encoding in xml header is changed to "cp866". I found a kind of solution which consists in initializing XmlTextReader with a StreamReader with a certain encoding instead of file name, like in the code below:

XmlTextReader reader = new XmlTextReader(new StreamReader(Server.MapPath(filename), Encoding.GetEncoding("cp866")));


The issue is that the directory which contains xml files is read only (I can not change it), so I get "System.UnauthorizedAccessException: Access to the path '' is denied.". Rather strange, because XmlTextReader initialized with a filename seems to read the files. Is there any solution, considering that program cannot modify or create files?

View 1 Replies

Web Forms :: Automatic File Reading / Check For New File Everyday And If The New File Is In The Folder Read It

Sep 20, 2010

I would like ask you for some ideas how can I write mechanism that will be automatically read files from folder. I don't know how to schedule the write task. I want to check for new file everyday and if the new file is in the folder read it.

View 2 Replies

Databases :: Reading CSV File From The Fileupload And Then Retrieve The Data?

Mar 4, 2010

1) I need to make reading CSV file from the fileupload and then retrieve the data.

2) I need to load CSV and the 3 columns rise two functions.

Load CSV data and then stored in a database, but I need to save storage space vary according to 3 column.

CSV Example:
1 column - Cat, 2 column - Black, 3 column - 1
1 column - Dog, 2 column - Brown, 3 column - 2
1 column - Cat, 2 column - Black, 3 column - 1
1 column - Dog, 2 column - Brown, 3 column - 2

Now I need to load the CSV in C # and column 3 to distinguish what the operation is carried out.When the load line in column 3 contain the value 1, so will save the table 'Cats' when the value 2 and is saved in the table "Dogs".(Note: Data are separated ";")

View 4 Replies

Reading Data From .XSLT File Populate Dropdown?

Feb 8, 2010

I would like to read some data from a .XSLT file to populate my dropdown, the outline is as follows

file name StaffDirectory.xslt

<xsl:stylesheet version="1.0" extension-element-prefixes="msxsl" exclude-result-prefixes="msxsl js dl" xmlns:xsl="http://www.w3.org/1999/XSL/Transform" xmlns:js="urn:custom-javascript" xmlns:msxsl="urn:schemas-microsoft-com:xslt" xmlns:dl="urn:datalist">

[Code].....

So id like to retrieve all values for ="IDAKRS0J" and populate a dropdown with this, is this possible ?

View 1 Replies

C# - Can Use HashTable For Temporary Data Storage After Reading Data From Database

Feb 5, 2010

I am looking for opinions and best coding practices.I need to get info from a database with a query such as SELECT this, that FROM MyDB (returning 2 fields). Would it be wrong to use a hashtable for temporary storage?Is there a better way to accomplish the same thing? What about if I am returning more than 2 fields, would it be best to step up to a DataSet or something?

public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
GetData();
[code]...

View 7 Replies

ADO.NET :: Unexpected End Of File While Parsing Name Occurred

Nov 3, 2010

I am reading XML file in the following code

[Code]....

when my xml file is big, I get the following error unexpected end of file while parsing name has occurred. Line 1, position 2034 the xmlData debug showed that not all the xml file is being read

[Code]....

I read that the memory of the string variable is not big enough to handle the xml file, what can I use to be able to read big xml files. my program works for small xml text.

View 1 Replies

C# - Excel File Parsing / Scraping Using .NET?

Jul 13, 2010

trying to parse an excel file. its structure is very complex. The possible way i know are.

Use Office introp libraries
Use OLEDB provider and read excel file in a dataset.

But the issue is of its complexity like some columns,cells or rows blank etc.

What are the best possible ways to do this ?

View 5 Replies

DataSource Controls :: Reading A Huge File From Data Base?

Oct 19, 2010

I have a 1.5 GB file into a table. I want to read It from server and create a file stream with it for save.

When I use DataAdapter.Fill(DataSet); code OutOfMemoryException occurs.

What should I do for read a hage file from data base?

View 8 Replies

Forms Data Controls :: Collections Versus Reading Database Every-time

Jan 18, 2010

1. I know about collections but I dont remember the precess. I know you drag a sqldatasource control on the form(Select everything in the database ie. selct *) and then delete it. But how do I use it i code.

Example. I need to select services where country=canada from the Agencies table.

2. I know how to manually pull data from an access database using the code below. I want to know how to pull data from a sql database just like the one below.

3. explain the difference between Collections and manually pulling it like the one bellow?

<code>
<script>
Stringpath = Server.Mappath = Server. MapPath(/website");
String connStr = Provider=Microsoft.Jet.OLEDB.4.0" +"DataSource="+path+
\Database;
OleDBConnnection conn = new OleDBConnection(connStr);
conn.open();
OleDbCommand cmd= new OleDBCommand();
cmd.COnnection = conn;
cmdCommandText = "Select * From [Suppliers];
OledbDataReader dr= cmd.ExecuteReader();
Response.write(dr.getvalue(1);

View 1 Replies

MVC :: Parsing Weather Channel Xml File Using Linq

Aug 31, 2010

I never used linq before and i'm having trouble parsing the xml file at

[Code]....
[Code]....
[Code]....

View 10 Replies

WCF / ASMX :: Add Service Reference Reading Svc File But Not Reading Service?

Mar 10, 2011

I was trying to go through this tutorial:

[URL]

but when I tried to add the service reference to the silverlight app, the Add Service Reference window would show me that there was a service file, but the node wouldn't expand to show the rest of the files that contain the services and what not. I got this error instead:

"An error occurred during the processing of a configuration file required to service this request. review the specific error details below and modify your configuration file appropriately."

"Parser Error Message:There is no service behavior named 'AdventureWorks_WebServer.Service1Behavior'."

"Metadata contains a reference that cannot be resolved: 'http://localhost:55579/Service1.svc'.

The server did not provide a meaningful reply; this might be caused by a contract mismatch, a premature session shutdown or an internal server error.

If the service is defined in the current solution, try building the solution and adding the service reference again."

here's my web.config file:

[Code]....

View 1 Replies







Copyrights 2005-15 www.BigResource.com, All rights reserved