473,799 Members | 2,840 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Adding Lines to Access Database

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 "outputfile 2" lines to be adjacent to the "outputfile 1"
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.t xt"
'Open the first file

sr = IO.File.OpenTex t(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.Str ingBuilder(line File1)
sb.Replace("C:" , "")
sb.Replace("x:" , "")
sb.Replace("\", "/")
sb.Replace("www root", "")
lineFile1 = sb.ToString()

'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(Inte rnet_Directory)
VALUES('" & lineFile1.ToStr ing & "')"
CreateStoredPro c(sSQL)

counter += 1
Loop
sr.Close()

File2 = "IISLog.txt "
sr = IO.File.OpenTex t(File2)
sSQL = ""

Do While sr.Peek <-1

lineFile2 = sr.ReadLine

'String Manipulation (Replace some unneeded text)

Dim sb2 As New System.Text.Str ingBuilder(line File2)
sb2.Replace("C: ", "")
sb2.Replace("x: ", "")
sb2.Replace("\" , "/")
sb2.Replace("ww wroot", "")
lineFile2 = sb2.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(IIS_ Logs) VALUES('" &
lineFile2.ToStr ing & "')"
CreateStoredPro c(sSQL)

counter2 += 1

Loop

sr.Close()
End Sub

Oct 27 '06 #1
5 1512
Why don't you read both input files at the same time? If you are confident
that they contain the same number of elements, then it should work.

Sub ReadFiles()
Dim File1 As String = "intDirectory.t xt"
Dim File2 As String = "IISLog.txt "
Dim sSQL As String
Dim lineFile1 As String
Dim lineFile2 As String

'Open the input files
Dim sr1 As StreamReader = IO.File.OpenTex t(File1)
Dim sr2 As StreamReader = IO.File.OpenTex t(File2)

'Loop through Directory Listing file to load filepaths
Do While sr.Peek <-1
lineFile1 = PrepareContent( sr1.ReadLine)
lineFile2 = PrepareContent( sr2.ReadLine)

sSQL = "INSERT INTO Comparison(Inte rnet_Directory, IIS_Logs) " & _
"VALUES ('" & lineFile1 & "', '" & lineFile2 & "')"
CreateStoredPro c(sSQL)
Loop
sr1.Close()
sr2.Close()
End Sub

Sub PrepareContent( ByVal origString As String) As String
Dim workArea As String

workArea = origString.Repl ace("C:", "")
workArea = workArea.Replac e("x:", "")
workArea = workArea.Replac e("\", "/")
workArea = workArea.Replac e("wwwroot", "")
Return workArea
End Sub

Of course, you should add in error handling just in case the files don't
match. Also, I beg of you to use Option Strict and Option Explicit. It will
mean more typing for you, but it will also help resolve hidden errors.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
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 "outputfile 2" lines to be adjacent to the "outputfile 1"
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.t xt"
'Open the first file
sr = IO.File.OpenTex t(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.Str ingBuilder(line File1)
sb.Replace("C:" , "")
sb.Replace("x:" , "")
sb.Replace("\", "/")
sb.Replace("www root", "")
lineFile1 = sb.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(Inte rnet_Directory)
VALUES('" & lineFile1.ToStr ing & "')"
CreateStoredPro c(sSQL)
counter += 1
Loop
sr.Close()
File2 = "IISLog.txt "
sr = IO.File.OpenTex t(File2)
sSQL = ""
Do While sr.Peek <-1

lineFile2 = sr.ReadLine

'String Manipulation (Replace some unneeded text)

Dim sb2 As New System.Text.Str ingBuilder(line File2)
sb2.Replace("C: ", "")
sb2.Replace("x: ", "")
sb2.Replace("\" , "/")
sb2.Replace("ww wroot", "")
lineFile2 = sb2.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(IIS_ Logs) VALUES('" &
lineFile2.ToStr ing & "')"
CreateStoredPro c(sSQL)
counter2 += 1

Loop

sr.Close()

End Sub

Oct 27 '06 #2
But they definately won't contain the same number of elements. One is a
file system directory and one is the iis log for that file system
directory. I'm trying to compare these two files and get a result.
Then, create a report.
Tim Patrick wrote:
Why don't you read both input files at the same time? If you are confident
that they contain the same number of elements, then it should work.

Sub ReadFiles()
Dim File1 As String = "intDirectory.t xt"
Dim File2 As String = "IISLog.txt "
Dim sSQL As String
Dim lineFile1 As String
Dim lineFile2 As String

'Open the input files
Dim sr1 As StreamReader = IO.File.OpenTex t(File1)
Dim sr2 As StreamReader = IO.File.OpenTex t(File2)

'Loop through Directory Listing file to load filepaths
Do While sr.Peek <-1
lineFile1 = PrepareContent( sr1.ReadLine)
lineFile2 = PrepareContent( sr2.ReadLine)

sSQL = "INSERT INTO Comparison(Inte rnet_Directory, IIS_Logs) " & _
"VALUES ('" & lineFile1 & "', '" & lineFile2 & "')"
CreateStoredPro c(sSQL)
Loop
sr1.Close()
sr2.Close()
End Sub

Sub PrepareContent( ByVal origString As String) As String
Dim workArea As String

workArea = origString.Repl ace("C:", "")
workArea = workArea.Replac e("x:", "")
workArea = workArea.Replac e("\", "/")
workArea = workArea.Replac e("wwwroot", "")
Return workArea
End Sub

Of course, you should add in error handling just in case the files don't
match. Also, I beg of you to use Option Strict and Option Explicit. It will
mean more typing for you, but it will also help resolve hidden errors.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
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 "outputfile 2" lines to be adjacent to the "outputfile 1"
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.t xt"
'Open the first file
sr = IO.File.OpenTex t(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.Str ingBuilder(line File1)
sb.Replace("C:" , "")
sb.Replace("x:" , "")
sb.Replace("\", "/")
sb.Replace("www root", "")
lineFile1 = sb.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(Inte rnet_Directory)
VALUES('" & lineFile1.ToStr ing & "')"
CreateStoredPro c(sSQL)
counter += 1
Loop
sr.Close()
File2 = "IISLog.txt "
sr = IO.File.OpenTex t(File2)
sSQL = ""
Do While sr.Peek <-1

lineFile2 = sr.ReadLine

'String Manipulation (Replace some unneeded text)

Dim sb2 As New System.Text.Str ingBuilder(line File2)
sb2.Replace("C: ", "")
sb2.Replace("x: ", "")
sb2.Replace("\" , "/")
sb2.Replace("ww wroot", "")
lineFile2 = sb2.ToString()
'INSERT INTO TABLE
sSQL = "INSERT INTO Comparison(IIS_ Logs) VALUES('" &
lineFile2.ToStr ing & "')"
CreateStoredPro c(sSQL)
counter2 += 1

Loop

sr.Close()

End Sub
Oct 27 '06 #3
In that case, I would need additional information about the data stored in
the two source files and how you want to report the final data. For instance,
from what you said it sounds like the first file contains a listing of all
directories in your web site, while the second file contains a list of the
files accessed within that same set of directories. Perhaps your goal is
to get a count, per directory, of file hits. But I may have interpreted your
report incorrectly.

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
But they definately won't contain the same number of elements. One is
a file system directory and one is the iis log for that file system
directory. I'm trying to compare these two files and get a result.
Then, create a report.

Oct 27 '06 #4
Ok, here's the situation.

I need to crawl the website to make a list of all the files on the
site.

The website list is sampled as followed:

/en/menu.htm
/exampl/examples/you/justin.htm

Also, i have to crawl one IIS log.

I Created a temp log file wherein sample entries are as follows:

/en/menu.htm
/thisisexample/you.html
/example/tom/test.html

There could be 1000 files in the file directory, but 678 in the IIS
Log. Get what i'm saying?

I am taking both these files, looping through them, and displaying them
in different fields, in one table in access. From there I can run a
query to compare them. Which ever entry in the website directory
listing does not match any entries in the IIS Log, I want to report on
those.

Anyway, that's my whole assignment. I certainly don't expect you to go
beyond what I requested first.

I hope you have better understood.

Justin

Oct 27 '06 #5
In this case I would create two distinct tables in your database, one for
each file. Load the contents of the first file into the first table, and
the second file into the second table. Then run queries that involve both
tables.

To get a list of all items in table 1 that are not in table 2, use this query.

SELECT DISTINCT FilePath FROM Table1
MINUS
SELECT DISTINCT FilePath FROM Table2

At least that works in Oracle. In SQL Server, use the EXCEPT keyword instead
of MINUS. I can't recall if Access uses either of these keywords. If neither
is supported, the following query will work as well.

SELECT DISTINCT FilePath FROM Table1
WHERE FilePath NOT IN (
SELECT DISTINCT FilePath FROM Table2)

-----
Tim Patrick
Start-to-Finish Visual Basic 2005
Ok, here's the situation.

I need to crawl the website to make a list of all the files on the
site.

The website list is sampled as followed:

/en/menu.htm
/exampl/examples/you/justin.htm
Also, i have to crawl one IIS log.

I Created a temp log file wherein sample entries are as follows:

/en/menu.htm
/thisisexample/you.html
/example/tom/test.html
There could be 1000 files in the file directory, but 678 in the IIS
Log. Get what i'm saying?

I am taking both these files, looping through them, and displaying
them in different fields, in one table in access. From there I can run
a query to compare them. Which ever entry in the website directory
listing does not match any entries in the IIS Log, I want to report on
those.

Anyway, that's my whole assignment. I certainly don't expect you to go
beyond what I requested first.

I hope you have better understood.

Justin

Oct 27 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
2701
by: cppaddict | last post by:
Hi, I have some code which uses std::map to associate cartesian POINTs with values. My current syntax for adding new (POINT,value) entries to the map is clunky -- it takes three lines for each entry. There must be a way to trim it down: <code> #include <map> #include <iostream>
7
781
by: Alex | last post by:
Hi all, I've found a module that I think will help me combine fields properly, but I'm unsure how to add or use it with Access 2000. Below is the module I'd like to add: http://www.mvps.org/access/modules/mdl0008.htm In Access, I goto Modules and create new. Leaving 'Option Compare Database' on top I paste the module code in and save - naming it fConcatFld. It saves fine, but when I use fConcatFld in my query, like below:
3
4887
by: Jim Heavey | last post by:
Trying to figure out the technique which should be used to add rows to a datagrid. I am thinking that I would want an "Add" button on the footer, but I am not quite sure how to do that. Is that the best method? Do you have a sample of how to do this?
4
1781
by: paul | last post by:
Hi, Im trying to add a dataset to the app_code directory using vs2005 \ SQL2005 beta 2. When I run through the wizard I select the option to auto create new Stored Procedures (Select, update, delete, insert commands) after already specifying a very basic select command that consists of two fields. All procedures are created fine and i'm able to save the xsd file. Then I create a new gridview in which i use the xsd file object as my
3
2346
by: Ankit Aneja | last post by:
I have a strange situation and I have no idea how to solve this. Its a Recruitment Search Page,in the Admin Page, for every button click event the Admin Person has to create a checkbox on the users page. So whenever the Admin person comes to know about the new category in the market he will be adding as different Sub-Categories for example ABAP, BDC etc..etc.. on every click event as Checkboxes. And these controls(checkboxes) should remain...
2
5073
by: Rico | last post by:
Hello, I'm formatting a report based on an existing controlled document. The document that I'm duplicating has a number of lines that the user fills our manually, but the database version of this document will fill the fields with data rather than the user hand writing entries. The problem I'm running into is when the last record prints, there are no more additional lines (i.e. if the document has 15 lines to be filled out, and if I...
8
3277
by: shumaker | last post by:
I'm wondering if adding an autonumber primary key will improve the performance of a multiuser access database on a network share. I have a website that lists many tips for improving performance of access, but doesn't mention primary keys. However, it seems logical to think that having no primary key means that when a user updates a record, the database has to do comparisons on multiple fields to identify the specific record being...
4
2347
by: sakopp | last post by:
I'm brand new at this and I'm making my first Access 2003 database. I would think my question is a real easy one. The database is real simple with only 1 table. I created a form to get input from the user. Using the button wizard, I created an "Add Record" button that the user clicks when finished. When the button is clicked the VB code listed below runs. But before the code is finished, I want to assign values to 2 fields in the table for...
6
2395
by: teddysnips | last post by:
I'm having trouble adding Access 2003 databases to Sourcesafe. I go to Tools, Sourcesafe, Add Database to Sourcesafe... at which point a message box appears saying "This database must be closed before you add it to Sourcesafe. Do you want Microsoft Access to close this database?" I click "Yes", and it displays the Sourcesafe Login screen. I log in, and select a location to add the project. And then nothing happens. Zilch. Nada. ...
0
10251
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10225
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
10027
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9072
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7564
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6805
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5585
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4139
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2938
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.