Register and join over 40,000 other developers!
Recent Topics
-
The Game You Are Waiting For?
WendellHarper - Dec 06 2020 01:21 PM
-
Quora and Reddit Backlinks
WendellHarper - Dec 06 2020 01:14 PM
-
Delete account
pindo - Jul 23 2020 01:33 AM
-
Print specific values from dictionary with a specific key name
Siten0308 - Jun 20 2019 01:43 PM
-
Learn algorithms and programming concepts
johnnylo - Apr 23 2019 07:49 AM
Recent Blog Entries
Recent Status Updates
Popular Tags
- networking
- Managed C++
- stream
- console
- database
- authentication
- Visual Basic 4 / 5 / 6
- session
- Connection
- asp.net
- import
- syntax
- hardware
- html5
- array
- mysql
- java
- php
- c++
- string
- C#
- html
- loop
- timer
- jquery
- ajax
- javascript
- programming
- android
- css
- assembly
- c
- form
- vb.net
- xml
- linked list
- login
- encryption
- pseudocode
- calculator
- sql
- python
- setup
- help
- game
- combobox
- binary
- hello world
- grid
- innerHTML

[SOLVED] Add Value From Text File To Database Using Vb.net And Ms Sql
Started by poojab, Jul 23 2012 10:42 PM
VB.NET textfile database VB.net MS SQL value
2 replies to this topic
#1
Posted 23 July 2012 - 10:42 PM
Hello Friends,
I want to know how can I add values from different text files to database using VB.net code....
To be more clear...
In my application.StartupPath I have a folder named PatientDetails
In this folder other folders will get created according to Patient id's
In this folder there will be the text files containing the patient complete details....
Now what I want is that the database shud get all the values from all the folders and save the values in the MS SQL database...
Can anyone help me on this???
Regards,
Pooja
I want to know how can I add values from different text files to database using VB.net code....
To be more clear...
In my application.StartupPath I have a folder named PatientDetails
In this folder other folders will get created according to Patient id's
In this folder there will be the text files containing the patient complete details....
Now what I want is that the database shud get all the values from all the folders and save the values in the MS SQL database...
Can anyone help me on this???
Regards,
Pooja
#2
Posted 24 July 2012 - 12:34 AM
I got the code working....
Find below
Find below
'open database connection Open_DB_Connection() Dim i As Integer = 1 Dim dir As DirectoryInfo = New DirectoryInfo(Application.StartupPath & "\Images\") 'get the number of folders in the main folder Dim number As Integer number = System.IO.Directory.GetDirectories(dir.ToString).Length Debug.Print("number: " + number.ToString) Dim myCommand As SqlCommand 'delete the data if any present in database Try Dim myCommandD As SqlCommand myCommandD = New SqlCommand("DELETE FROM Test.dbo.Test3project", Connection) myCommandD.ExecuteNonQuery() 'check if main folder is empty If number = 0 Then MsgBox("No files found") Else 'get the array of directories Dim mainfolder As DirectoryInfo() = dir.GetDirectories() Dim foldername As DirectoryInfo For Each foldername In mainfolder Debug.Print("folder name: " + foldername.ToString) Dim sr As StreamReader = New StreamReader(Application.StartupPath + "\Images\" + foldername.ToString + "\patientreg.txt") 'read the content of the file Dim line As String = sr.ReadLine() 'split the file according to the separator Dim fields() As String = line.Split("*") 'insert the data into database myCommand = New SqlCommand("INSERT INTO Test.dbo.Test3project VALUES('" & fields(0) & "','" & fields(1) & "', '" & fields(2) & "', '" & fields(3) & "', '" & fields(4) & "','" & fields(5) & "','" & fields(6) & "')", Connection) Debug.Print("Query: " + myCommand.CommandText) myCommand.ExecuteNonQuery() Next MsgBox("Saved...showing data to datagrid") 'showing database data to datagrid Try Dim myCommand1 As New SqlCommand With myCommand1 .CommandText = "select * from Test.dbo.Test3project" .CommandType = CommandType.Text .Connection = Connection End With Dim dt As New DataTable dt.Load(myCommand1.ExecuteReader) With DataGridView1 .AutoGenerateColumns = True .DataSource = dt End With Catch ex As Exception MsgBox(ex.Message) End Try End If Catch ex As Exception MsgBox(ex.Message) End Try Close_DB_Connection()
#3
Posted 24 July 2012 - 03:50 AM
This topic has been marked as SOLVED. If you have a similar question or topic, go back to the subforum and start a new topic to continue discussions.
I'm a System developer at XLENT Consultant Group mainly working with SugarCRM.
Please DO NOT send mail or PM to me with programming questions, post them in the appropriate forum instead, where I and others can answer you.
Also tagged with one or more of these keywords: VB.NET, textfile, database, VB.net, MS SQL, value
Language Forums →
Python →
Print specific values from dictionary with a specific key nameStarted by Siten0308, 20 Jun 2019 ![]() |
|
![]() |
||
Language Forums →
Databases →
SOLVED: Conditional insertion of rows via MySQLStarted by PuddingEatsPanda, 19 Mar 2016 ![]() |
|
![]() |
||
Tutorial Forums →
Visual Basic Tutorials →
Visual Basic .NET Tutorial - How to add google maps in a VB programme Part 2/2 - codecall.netStarted by Cobus, 09 Feb 2016 ![]() |
|
![]() |
||
General Forums →
General Programming →
sql database 2008Started by rhysgardner, 31 Jan 2016 ![]() |
|
![]() |
||
General Forums →
General Computing →
What are some free database servers for testing cross platform application?Started by BlueBox, 03 Jan 2016 ![]() |
|
![]() |
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download