Click to See Complete Forum and Search --> : displaying object elements
Mathie
03-09-2006, 08:25 AM
Hello. I was wondering if anyone could help me by telling me how in the world you do this:
i have made a class named Business that has several properties (name, address, phone number....) and that works. what i want to do now is i want to try and find a way to show all of the instances of that objects parameters on the webform,. i need a way to to have some sort of loop that can allow me to enter in all the data on the screen, sort of like this:
Name (business objext 1)
Address
Phone Number
City, zipcode
----------------
Name (business objext 2)
Address
Phone Number
City, zipcode
----------------
........
and keep onm going until all the objexts have been shown. i dont initially know how many there are goin to be since each search brings back a different amount (from an XML feed). if someone could please helkp me that would be great thank you!
Dim adOpenForwardOnly, adLockReadOnly, adCmdTable
adOpenForwardOnly = 0
adLockReadOnly = 1
adCmdTable = 2
Dim objConn, objRS
Set objConn = Server.CreateObject("ADODB.Connection")
Set ObjRS = Server.CreateObject("ADODB.Recordset")
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=EnterYourDatabaseSourceHere;" &_
"Persist Security Info=False"
ObjRS.Open "BusinessTable", ObjConn, adOpenForwardOnly, adLockReadOnly, adCmdTable
While Not ObjRS.EOF
Response.Write ObjRS("BizName") & vbCrLf
Response.Write ObjRS("BizAddress") & vbCrLf
Response.Write ObjRS("BizPhone") & vbCrLf
Response.Write ObjRS("BizCity") & ", "
Response.Write ObjRS("BizZip") & vbCrLf & vbCrLf & vbCrLf
Wend
objRS.Close
objConn.Close
Set objRS = Nothing
Set objConn = Nothing
You need to change the fields in bold. Hope this helps. Let me know if you need anything else.
Cheers
Mathie
03-09-2006, 12:48 PM
Hi, thank you for responding to my question, but i have 2 questions relating to this, what will be my EnterYourDatabaseSourceHere? I mean, i am getting the data from an array of objects -
private Business[] list;
and my other question is, how do you exactly write this part of the code, it keeps on asking me for ; -
objConn.Open "Provider=Microsoft.Jet.OLEDB.4.0;" &_
"Data Source=EnterYourDatabaseSourceHere;" &_
"Persist Security Info=False"
thank you again for responsing, and if i could just get some last part on this, i should be 100%
The script I wrote is designed to obtain the information from a database.
Enter the source to where your database is located. For example, if you're testing it on your machine, it could be something like "C:\databases\BizInfo.mdb".
Cheers
Mathie
03-09-2006, 12:58 PM
The thing is, is that i dont have a database, I am reading an XML feed off of the internet, and then creating objects named business afterwards to put the data in from the related data i needed from the xml feed. should i make a database? and if so, how then do i add elements to the database when i wont have my data until after i run the project since it gets the data from a XML feed?
I really appriciate this help Jay, thank you very much
You're welcome Mathie. I guess I should learn to read the entire question rather than just skim through it :rolleyes: .
I'd love to help you but I'm not too familiar with XML. Maybe this will help:
http://bytescout.com/how_to_display_rss_using_asp.html
http://www.freevbcode.com/ShowCode.Asp?ID=5665
Cheers
Mathie
03-09-2006, 01:20 PM
nono, i think that you are right about what u said on the first thread, i mean, i have all the data after the aspx file starts, its put into object, im not dealing with XML anymore, after the code i have
private Business[] list;
list[0] = an object with parameters
.......
list[n] = an object with parameters
all i need to do now is write it the the html page.
Mathie
03-09-2006, 02:52 PM
hey, i am so sorry i keep on asking u stuff, but actually this time i got all my data to display on the screen with this:
for(int i = 0; i < list.Length; i++)
{
string name = list[i].GetName();
string address = list[i].GetAddress();
string city = list[i].GetCity();
string state = list[i].GetState();
string zip = list[i].getZip();
string url = list[i].getURL();
Response.Write(name);
Response.Write("\n");
Response.Write(address);
Response.Write("\n");
Response.Write(city);
Response.Write("\n");
Response.Write(state);
Response.Write("\n");
Response.Write(zip);
Response.Write("\n");
Response.Write(url);
Response.Write("\n");
however there is only one thing wrong now i wanted it to be like this:
name
address
city, state zip
phone
but it is like this:
BUSINESS FORUM 9297 BURTON WAY STE 100 BEVERLY HILLS CA 90210 http://www.bizforum.org ARABIA ONLINE BOX 2853 BEVERLY HILLS CA 90213 http://www.arabia.com LOS ANGELES JEWISH EVENTS BOX 16002 BEVERLY HILLS CA 90209 http://www.laje.blogspot.com LOS ANGELES JEWISH EVENTS BOX 16002 BEVERLY HILLS CA 90209 http://www.laje.blogspot.com VALOR ENTERTAINMENT BOX 16539 BEVERLY HILLS CA 90209 http://www.almasri.com AMEN RA FILMS INCORPORATED 301 N CANON DR STE 228 BEVERLY HILLS CA 90210 http://www.alandfaraway.com FGM ENTERTAINMENT 301 N CANON DR STE 328 BEVERLY HILLS CA 90210 http://www.avenue-entertainment.com DOMAINATERIA 270 N CANON DR STE 1031 BEVERLY HILLS CA 90210 http://www.domainateria.com CHEVRON STATION 9378 WILSHIRE BLVD BEVERLY HILLS CA 90212 http://www.chevron.com
how come when i am using the \n it is just seperating the different variables vy just a space, and not my a line?
Check out your new thread. I posted the answer there.
Cheers