Upload txt data to MS SQL Database (Using C# and ASP.NET)
Hi, it's me agian... I was asked to do reasearch on how to upload a txt file's data into a MS SQL Database (corresponding columns etc.) I've searched a bit on the internet but don't find what i'm looking for... I just want to ask does anyone have an idea of where i can go and look for information on this. (I'm still very new to C# and ASP.NET programming) (It's so that i can present this topic in class and implement it in my class project) I would really appreciate any suggestions, and i thank you in advance!
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0
Lol tnx i just got that page before i saw your reply tnx!
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0
Oky i've got it partially working now. My only question now is will i be able to have a autonumber column aswell in the database table so that the autonumber keeps on adding numbers as i upload my data into the table? (i hope so but i know that it will most probably only work with an insert statement? right or wrong?)
I saw that to skip the first row you can simply say FIRSTROW = 2 and so i tried FIRSTCOLUMN = 2 but doesn't work. Here is my code:
BULK INSERT dbo.testTBLUpload
FROM 'C:\Users\GOgGA\Desktop\upload1.txt'
WITH (
FIRSTROW = 2,
FIELDTERMINATOR = '|',
ROWTERMINATOR = '\n'
)
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0
O snd sorry for this little bit of SQL code in the C# section on the forum. But this is for my C# class so yea!
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0
CREATE TABLE mytable
(
/*id INT IDENTITY(1,1) PRIMARY KEY,*/
Fname text,
Surname text,
Tel text,
Salary DECIMAL(18,2)
);
text file:
Hein|Oosthuyzen|0123313470|15489.62
Johan|du Toit|0126547896|13240.27
Nico|Fourie|0124784532|14500.20
Shaun|Venter|0123546987|16320.12
Burnabe|Jordaan|0124872134|12480.80
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0
tnx i'll try it out and let you know!
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0
Sorry i thought it worked but i see now that i still can't have a autonumber column in my database...? the bulk insert works from the first column onwards and i need to have the autonumber column...Any further suggestions?
phoenix_dwarf
Junior Poster in Training
57 posts since May 2009
Reputation Points: 11
Solved Threads: 0