Hi Guys, since I've done nothing but ask questions these last few weeks to get my first application up and running I thought it was about time to share the wealth and help out a newbie like me since you all did the same, thanks for all that replied to me.
This code will save a csv file to a dir, you can then use this to bulk insert the information to a specific table in your DB, this is done with asp.net vb and sql, I'm using an mdf for this. I also gave admins the ability to delete the info in there before they actually import the csv. - <script runat="server">
-
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.
-
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.
-
' Will overwrite existing file of same name
-
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 DeleteAllButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
Dim SQLConn As New System.Data.SqlClient.SqlConnection
-
SQLConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PostOffice.mdf;Integrated Security=True;User Instance=True"
-
Dim strInsert As String
-
Dim cmdInsert As SqlCommand
-
strInsert = "DELETE FROM LocalPostOffice WHERE(ID > 0)"
-
cmdInsert = New SqlCommand(strInsert, SQLConn)
-
SQLConn.Open()
-
cmdInsert.ExecuteNonQuery()
-
SQLConn.Close()
-
End Sub
-
-
Sub ImportButton_Click(ByVal sender As Object, ByVal e As System.EventArgs)
-
Dim SQLConn As New System.Data.SqlClient.SqlConnection
-
SQLConn.ConnectionString = "Data Source=.\SQLEXPRESS;AttachDbFilename=|DataDirectory|\PostOffice.mdf;Integrated Security=True;User Instance=True"
-
Dim strInsert As String
-
Dim cmdInsert As SqlCommand
-
strInsert = "BULK INSERT [LocalPostOffice] FROM [c:\Inetpub\wwwroot\MerlinLocalPostOfficeApp\Data\csv.txt] WITH (FIELDTERMINATOR = ',')"
-
cmdInsert = New SqlCommand(strInsert, SQLConn)
-
SQLConn.Open()
-
cmdInsert.ExecuteNonQuery()
-
SQLConn.close()
-
End Sub
-
-
</script>
Hope this helps someone in the future.
0 8971 Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Diego |
last post by:
HI, I'm trying yo improve the performance of the following piece of
code.
Here I'm archiving Items that are done processing to Archive Tables.
I believe that if I use BULK INSERTS/SELECTS/UPDATES this process will
move much faster.
Can someone suggest me a way to do it?
Thanks
declare
|
by: Chris |
last post by:
Any help would be appreciated.
I am running a script that does the following in succession.
1-Drop existing database and create new database
2-Defines tables, stored procedures and functions in the database
3-Imports data using bulk insert
4-Analyzes data using stored procedures
I would like to improve the performance of the analysis in step 4 by
|
by: php newbie |
last post by:
Hello,
I am trying to load a simple tab-delimited data file to SQL Server. I
created a format file to go with it, since the data file differs from
the destination table in number of columns.
When I execute the query, I get an error saying that only sysadmin or
bulkadmin roles are allowed to use the BULK INSERT statement. So, I
proceeded with the Enterprise Manager to grant myself those roles.
However, I could not find sysadmin or...
|
by: iqbal |
last post by:
Hi all,
We have an application through which we are bulk inserting rows into a
view. The definition of the view is such that it selects columns from
a table on a remote server. I have added the servers using
sp_addlinkedserver on both database servers.
When I call the Commit API of oledb I get the following error:
Error state: 1, Severity: 19, Server: TST-PROC22, Line#: 1, msg:
|
by: pk |
last post by:
Sorry for the piece-by-piece nature of this post, I moved it from a
dormant group to this one and it was 3 separate posts in the other
group. Anyway...
I'm trying to bulk insert a text file of 10 columns into a table with
12. How can I specify which columns to insert to? I think format
files are what I'm supposed to use, but I can't figure them out. I've
also tried using a view, as was suggested on one of the many websites
I've...
| |
by: Philip Boonzaaier |
last post by:
I want to be able to generate SQL statements that will go through a list of
data, effectively row by row, enquire on the database if this exists in the
selected table- If it exists, then the colums must be UPDATED, if not, they
must be INSERTED.
Logically then, I would like to SELECT * FROM <TABLE>
WHERE ....<Values entered here>, and then IF FOUND
UPDATE <TABLE> SET .... <Values entered here> ELSE
INSERT INTO <TABLE> VALUES <Values...
|
by: Zarrin |
last post by:
Hello,
I read several articles of newsgroup about the bulk delete, and I found
one way is to:
-create a temporary table with all constraints of original table
-insert rows to be retained into that temp table
-drop constraints on original table
-drop the original table
-rename the temporary table
|
by: ozkhillscovington |
last post by:
We have sp's in place that do BULK INSERTS from txt files into the tables. This works fine, however they have asked us to add a field that identifies accounting ctr. The only thing that identifies accounting ctr is the last three letters of the text file being used for the BULK INSERT.
How would you suggest that I do this? Is there a way to add a default value to the .fmt or schema files for the text fields, or in the BULK INSERT...
|
by: shreyask |
last post by:
I have been working on doing bulk updates and inserts through sqlapi++ using a bulk udpate extention library, developed, a long time ago, internally. The database is oracle. The bulk inserts/updates are done in batches of 50K. I am facing a very peculiar performance issue with regard to these bulk operations.
The initial batch of bulk insert (50K records) is finished within 3 seconds; while the next similar batch for bulk insert or update...
|
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it.
First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
|
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth.
The Art of Business Website Design
Your website is...
| |
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,...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own....
Now, this would greatly impact the work of software developers. The idea...
|
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...
|
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();...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
|
by: muto222 |
last post by:
How can i add a mobile payment intergratation into php mysql website.
| |
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...
| |