Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
CODE PROJECT For Those Who Code
  • Home
  • Articles
  • FAQ
Community
  1. Home
  2. General Programming
  3. .NET (Core and Framework)
  4. reading a string from a txt file & insert it in a database table?

reading a string from a txt file & insert it in a database table?

Scheduled Pinned Locked Moved .NET (Core and Framework)
questioncsharpdatabase
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    starist
    wrote on last edited by
    #1

    plz how can i read a string from a txt file then insert it in a database table using C# in visualstudio2005 ?

    V 1 Reply Last reply
    0
    • S starist

      plz how can i read a string from a txt file then insert it in a database table using C# in visualstudio2005 ?

      V Offline
      V Offline
      Vaibhav Sharma
      wrote on last edited by
      #2

      Ok as regards your first qt. >> Use the My.Computer.FileSystem.ReadAllText() function to read the text from the text file that you want the data to be imported from. Dump the string returned by this into a local called importedData >> As for the Database code, you should have specified the provider, but here is it for Access. Dim oledbCn As New System.Data.OledbConnection(connectionString) oledbCn.Open() Dim oledbCmd As New System.Data.OledbCommand(commandString,oledbCn) If oledbCmd.ExecuteNonQuery()>0 Then MessageBox.Show("Data imported to database correctly.") Else MessageBox.Show("Data import failed.") End If As you may be knowing, connectionString for Access will be "Microsoft.Jet.OLEDB.4.0; Data Source=MyDatabase.mdb" commandString would be the T-SQL statement like "INSERT INTO TableName(colName1,colName2,...) VALUES('" & importedData & "',...)" I guess that is fairly a very Beginners job in .NET and you should be having no problems whatsoever using the above snippets. In case of problems always refer back and we will be there for u. Happy Coding :)

      Regards, Vaibhav Sharma

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups