By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,335 Members | 2,281 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,335 IT Pros & Developers. It's quick & easy.

Adding tables and fields to database using vb.net

P: n/a
Hi everyone,

I need some help. I'm placing text files into a created database using
vb.Net. The problem is that, i need two seperate sql statements to add
both files because they are in different loops. My output comes out to
be as Follows:
TABLE
----------------------------------------------------
Field1 Field2
outputfile1
outputfile1
outputfile1
outputfile1
outputfile1
outputfile2
outputfile2
outputfile2
outputfile2
-----------------------------------------------------
I declared both fields Nullable so I wouldn't get an error, complaining

that the fields cannot be Null.
I need the "outputfile2" lines to be adjacent to the "outputfile1"
files. I understand why this is happening, I just can't think of
another way of adding the fields.
My code is as follows:

---------------------------------------------------------------------------------------------------
Sub ReadFiles()
File1 = "intDirectory.txt"
'Open the first file
sr = IO.File.OpenText(File1)
'Initialize counter
'Loop through Directory Listing file to load filepaths into an
array
Do While sr.Peek <-1
lineFile1 = sr.ReadLine
Dim sb As New System.Text.StringBuilder(lineFile1)
sb.Replace("C:", "")
sb.Replace("x:", "")
sb.Replace("\", "/")
sb.Replace("wwwroot", "")
lineFile1 = sb.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(Internet_Directory)
VALUES('" & lineFile1.ToString & "')"
CreateStoredProc(sSQL)
counter += 1
Loop
sr.Close()
File2 = "IISLog.txt"
sr = IO.File.OpenText(File2)
sSQL = ""
Do While sr.Peek <-1
lineFile2 = sr.ReadLine
'String Manipulation (Replace some unneeded text)
Dim sb2 As New System.Text.StringBuilder(lineFile2)
sb2.Replace("C:", "")
sb2.Replace("x:", "")
sb2.Replace("\", "/")
sb2.Replace("wwwroot", "")
lineFile2 = sb2.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(IIS_Logs) VALUES('" &
lineFile2.ToString & "')"
CreateStoredProc(sSQL)
counter2 += 1
Loop
sr.Close()
End Sub
---------------------------------------------------------------------------------------------------

Oct 27 '06 #1
Share this Question
Share on Google+
2 Replies


P: n/a
Justin Fancy wrote:
I need some help. I'm placing text files into a created database using
vb.Net. The problem is that, i need two seperate sql statements to add
both files because they are in different loops.
I don't begin to claim I know what code you need in .Net, but your 1st query
can be an append query and the 2nd query must be an update query for Field2.
How you're going to line up the right records unless you have a primary key
beats me.

--
Message posted via AccessMonster.com
http://www.accessmonster.com/Uwe/For...ccess/200610/1

Oct 27 '06 #2

P: n/a
Assuming that the data in the two files is ordered identically and that the
data in Line1
of FileA belongs with data in Line1 of FileB then:

Open both files under different file handles; walk down both files at the
same time(one loop);
store the data from FileA in a variable called DataA and the data from FileB
in a variable
called DataB; have your Sql statement use both variables to append to each
field in one append; procede down the files until you hit (hopefully at the
same time) the EOF.

"Justin Fancy" <ju*********@gmail.comwrote in message
news:11*********************@b28g2000cwb.googlegro ups.com...
Hi everyone,

I need some help. I'm placing text files into a created database using
vb.Net. The problem is that, i need two seperate sql statements to add
both files because they are in different loops. My output comes out to
be as Follows:
TABLE
----------------------------------------------------
Field1 Field2
outputfile1
outputfile1
outputfile1
outputfile1
outputfile1
outputfile2
outputfile2
outputfile2
outputfile2
-----------------------------------------------------
I declared both fields Nullable so I wouldn't get an error, complaining

that the fields cannot be Null.
I need the "outputfile2" lines to be adjacent to the "outputfile1"
files. I understand why this is happening, I just can't think of
another way of adding the fields.
My code is as follows:

---------------------------------------------------------------------------------------------------
Sub ReadFiles()
File1 = "intDirectory.txt"
'Open the first file
sr = IO.File.OpenText(File1)
'Initialize counter
'Loop through Directory Listing file to load filepaths into an
array
Do While sr.Peek <-1
lineFile1 = sr.ReadLine
Dim sb As New System.Text.StringBuilder(lineFile1)
sb.Replace("C:", "")
sb.Replace("x:", "")
sb.Replace("\", "/")
sb.Replace("wwwroot", "")
lineFile1 = sb.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(Internet_Directory)
VALUES('" & lineFile1.ToString & "')"
CreateStoredProc(sSQL)
counter += 1
Loop
sr.Close()
File2 = "IISLog.txt"
sr = IO.File.OpenText(File2)
sSQL = ""
Do While sr.Peek <-1
lineFile2 = sr.ReadLine
'String Manipulation (Replace some unneeded text)
Dim sb2 As New System.Text.StringBuilder(lineFile2)
sb2.Replace("C:", "")
sb2.Replace("x:", "")
sb2.Replace("\", "/")
sb2.Replace("wwwroot", "")
lineFile2 = sb2.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(IIS_Logs) VALUES('" &
lineFile2.ToString & "')"
CreateStoredProc(sSQL)
counter2 += 1
Loop
sr.Close()
End Sub
---------------------------------------------------------------------------------------------------

Oct 30 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.