Upload txt data to MS SQL Database (Using C# and ASP.NET)

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2009
Posts: 29
Reputation: phoenix911 is an unknown quantity at this point 
Solved Threads: 0
phoenix911 phoenix911 is offline Offline
Light Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #11
Oct 2nd, 2009
Originally Posted by vuyiswamb View Post
Remove the First Column and let SQl add it for you as an identity Column.

hmmm that actually sounds the obvious ... but there wasnt a column in the textfile which has numbers for the autonumber field
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 158
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #12
Oct 2nd, 2009
Can you Post your TextFile and a Create Script of your SQl Table and i will give you an Exact code to write.

kind Regards

Vuyiswa Maseko
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 29
Reputation: phoenix911 is an unknown quantity at this point 
Solved Threads: 0
phoenix911 phoenix911 is offline Offline
Light Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #13
Oct 2nd, 2009
itll be posted now, give a sec plz...

and thanx
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 158
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
1
  #14
Oct 2nd, 2009
ok
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 40
Reputation: phoenix_dwarf is an unknown quantity at this point 
Solved Threads: 0
phoenix_dwarf phoenix_dwarf is offline Offline
Light Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #15
Oct 2nd, 2009
  1. CREATE TABLE mytable
  2. (
  3. /*id INT IDENTITY(1,1) PRIMARY KEY,*/
  4. Fname text,
  5. Surname text,
  6. Tel text,
  7. Salary DECIMAL(18,2)
  8. );

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
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 158
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #16
Oct 2nd, 2009
Here is your Solution

  1. SqlConnection con =new SqlConnection(@"User id=sa;Password=oops;Server=VUYISWA\SQLEXPRESS;Database=Vuyiswa");
  2.  
  3. SqlCommand cmdinsert = new SqlCommand();
  4.  
  5. cmdinsert.CommandText=@"BULK INSERT mytable FROM 'C:\WebSite29\Data.txt' WITH (FIELDTERMINATOR = '|', ROWTERMINATOR = '\n' );";
  6.  
  7. cmdinsert.CommandTimeout = 0;
  8.  
  9. cmdinsert.CommandType= CommandType.Text;
  10.  
  11. cmdinsert.Connection = con;
  12.  
  13. try
  14. {
  15. con.Open();
  16.  
  17. cmdinsert.ExecuteNonQuery();
  18.  
  19. }
  20. catch(SqlException ex)
  21. {
  22.  
  23. Label1.Text = ex.Message.ToString();
  24. }
  25. finally
  26. {
  27. if(con != null)
  28. {
  29. con.Close();
  30. }
  31. }

Kind Regards

Vuyiswa
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 40
Reputation: phoenix_dwarf is an unknown quantity at this point 
Solved Threads: 0
phoenix_dwarf phoenix_dwarf is offline Offline
Light Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #17
Oct 2nd, 2009
tnx i'll try it out and let you know!
Reply With Quote Quick reply to this message  
Join Date: Mar 2007
Posts: 158
Reputation: vuyiswamb is an unknown quantity at this point 
Solved Threads: 5
vuyiswamb's Avatar
vuyiswamb vuyiswamb is offline Offline
Junior Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #18
Oct 2nd, 2009
No Problem and dont Forget to mark the post as resolved and give me my reputation. am going home now enjoy your weekend

Kind Regards

Vuyiswa Maseko
Few companies that installed computers to reduce the employment of clerks have realized their expectations.... They now need more and more expensive clerks even though they call them "Developers" or "Programmers."
Reply With Quote Quick reply to this message  
Join Date: May 2009
Posts: 40
Reputation: phoenix_dwarf is an unknown quantity at this point 
Solved Threads: 0
phoenix_dwarf phoenix_dwarf is offline Offline
Light Poster

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #19
Oct 2nd, 2009
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?
Reply With Quote Quick reply to this message  
Join Date: Jul 2009
Posts: 969
Reputation: DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough DdoubleD is a jewel in the rough 
Solved Threads: 207
DdoubleD DdoubleD is offline Offline
Posting Shark

Re: Upload txt data to MS SQL Database (Using C# and ASP.NET)

 
0
  #20
Oct 2nd, 2009
Originally Posted by phoenix_dwarf View Post
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?
Seems to me you could add/insert an autonumber column after the bulk insert completes: How to: Create an Autonumber DataColumn
Reply With Quote Quick reply to this message  
Reply

Tags
c#, sql, uploadatextfile

Message:


Thread Tools Search this Thread



Tag cloud for c#, sql, uploadatextfile
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC