Retrieving record from access to array

delion

Member
Joined
Apr 27, 2007
Messages
7
Programming Experience
Beginner
How to retriving record from access field and save it in array?
My field contain data record in text from email subject like : "Re: how to buy..."
I need to save each record in an array?
I really frustated
:(

Thanks :)
 
Hi, i think the most simple way to do this would be to just use a simple ado.net connection, here is an example:

(NOTE: writing this if the top of my head so it may be buggy, note this assumes you have a Connection String set up. in this example its called CoreV1ConnectionString)

VB.NET:
Dim connectionstring As String = My.Settings.CoreV1ConnectionString
Dim theDatabase As New SqlClient.SqlConnection(connectionstring)
theDatabase.Open()
 
Dim array() As Array
Dim counter As Integer
Dim SQLstatement As New SqlClient.SqlCommand("SELECT EmailSubject FROM tblEmails", theDatabase)
Dim QueryResults As SqlClient.SqlDataReader = SQLstatement.ExecuteReader()
counter = 0
Do While QueryResults.Read()
   array(counter) = QueryResults("EmailSubject")
   counter = counter + 1
Loop
'now we have an array of data, redim it to its correct site and preserve the data in it
ReDim Preserve array(array(counter))
QueryResults.Close()
SQLstatement.Dispose()
'tidy up
SQLstatement = Nothing
theDatabase.Close()
theDatabase.Dispose()

good luck :D

Regards,

HeavenCore
 
Thanks you HeavenCote :)

Btw my case like this
1.I have database with 3 coloumn = ID,sbjMail,bdMail
2.One ID refer to one mail contain sbj and body
3.I want to parse each word from mail and save it in array for each word
4.I want to make new tabel and each record save each word from array, also ID from mail appear in that new tabel

How to make it ? :(

Help Please

Thanks you
 
that sounds like a very inefficient way of doing something, if the email is large the arrays could be massive, can i ask what you are doing this for?

Anyways, you would use the same code as i exampled earlier but this time in the read loop, read in both subj and body into their own arrays:

VB.NET:
Do While QueryResults.Read()
array(counter) = QueryResults("sbjMail")
array2(counter) = QueryResults("bdMail")
array3(counter) = QueryResults("id")
counter = counter + 1
Loop

(dont forget to DIM the arrays are ReDim Preserve afterwards)

ok, now you want to break each of the above arrays down into another array?

So loop through the above arrays and use split to populate 2 new arrays with a pointer for every word. First we need to identify which array pointer we need to look at based on user input i suppose? So

VB.NET:
Dim RequestedEmailID as integer
RequestedEmailID = txtRequest.text
Dim Counter2 as integer
Dim ArrayPointer as integer
 
For Each itm In array3 'array 3 is our array of ID numbers
if array3(Counter2) = RequestedEmailID then
ArrayPointer = Counter2
End If
Counter2 = Counter2 + 1
Next itm
So we now know where in Array and Array2 our information is coming from, so now we can simple split them into arrays as follows:

VB.NET:
Dim WordsArray() as String
WordsArray = Array(ArrayPointer).Split(" ")
 
Dim WordsArray2() as String
WordsArray2 = Array2(ArrayPointer).Split(" ")
And that should do it, again written of the top of my head so may be buggy, Although looking at this it seems very in-efficient, perhaps you should be doing this some other way?

But yea, hope that helps.

Regards

HeavenCore

EDIT: corrected a few bits
 
Last edited:
How to retriving record from access field and save it in array?
My field contain data record in text from email subject like : "Re: how to buy..."
I need to save each record in an array?
I really frustated
:(

Thanks :)

read the DW2 link in my signature, section on creating a simple application.

DO NOT USE AN ARRAY.. they are too simplistic for this purpose. The dw2 link will teach you about things like datasets, datatables and how they work.
 
VB.NET:
Dim connectionstring As String = My.Settings.CoreV1ConnectionString
Dim theDatabase As New SqlClient.SqlConnection(connectionstring)
theDatabase.Open()
 
Dim array() As Array
Dim counter As Integer
Dim SQLstatement As New SqlClient.SqlCommand("SELECT EmailSubject FROM tblEmails", theDatabase)
Dim QueryResults As SqlClient.SqlDataReader = SQLstatement.ExecuteReader()
counter = 0
Do While QueryResults.Read()
   array(counter) = QueryResults("EmailSubject")
   counter = counter + 1
Loop
'now we have an array of data, redim it to its correct site and preserve the data in it
ReDim Preserve array(array(counter))
QueryResults.Close()
SQLstatement.Dispose()
'tidy up
SQLstatement = Nothing
theDatabase.Close()
theDatabase.Dispose()

If possible, please avoid teaching newbies this style of coding. It's very old, not well encapsulated and will probably lead them on to all manner of sins such as "SELECT * FROM tbl WHERE col = '" & var & "'"

Instead, you can save yourself a lot of hard work by pointing them to the tutorials prepared by microsoft, and you will be starting them off with a better approach to database interaction
 
yea, as i said in my post:

that sounds like a very inefficient way of doing something, if the email is large the arrays could be massive, can i ask what you are doing this for?

i only gave an array example as this is what he asked for, surly datasets/recordsets would be more suitable, but he has not come back yet saying what he wanted to use arrays for.

But yea message received m8 :D
 
ps; Bolton? You poor soul.. Still, the shopping is good and the girls that arent tanaholics are quite pretty ;)
 
I want to tokenization the email, so I can classification it
Use Naive Bayesian :(
Btw where I can get Naive Bayesian code in vb.net 2005 ?

Help Please
 
to HeavenCore
I already try your code, and I have problem in:
ReDim Preserve array(array(counter))
There green line under :array(counter)

Thanks for tour help :)
 
ya, he said he was writing it using his head/guess, and didnt have the IDE.. It means it might need you to do a bit of work also. I know you'd love us to do it for you for free, but it wont help you learn much, so have a play and see how you go.. (and if you'd read the DW2 link you wouldnt have this problem at all)
 
Hi Dellion, find the line:

Dim array() As Array
at the beginning, i assumed you would change the 'As Array' to 'As String' or whatever would be best for your use but i suspect you have just copied and not changed it, try changing it to

VB.NET:
[/COLOR]
[COLOR=black]Dim Array() As String[/COLOR]
[COLOR=black]

But yea, Please Please Please read the Data Walkthroughs (DW2 in Cjards's Sig) they will help you alot more than us trying to guess what you are doing.

As for Naive Bayes classification, this is VERY specific code and you may be better reading up on how it works before even trying to implement it, a good resource is here: http://paul.luminos.nl/documents/show_document.php?d=198 , also wikipedia is your friend :D.

GL

HC.
 
Back
Top