storing ASP object in database

Results 1 to 2 of 2

Thread: storing ASP object in database

  1. #1
    Join Date
    Dec 1969

    Default storing ASP object in database

    hi!im trying to store an object in an SQL Server 200 database<BR>I have a class written in ASP, say Car.I create an object of it and i want to store the object as a table field.i created a table named tryclass as follows<BR>tryclass<BR>srno int identity(1,1) primary key<BR>obj varbinary 2000 null<BR><BR>my class definition is as follows<BR>&#060;%<BR> class car<BR> private color<BR> private speed<BR> <BR> private sub class_initialize()<BR> speed=0<BR> color="blue"<BR> end sub<BR> <BR> public property get currentspeed<BR> currentspeed=speed<BR> end property<BR> <BR> public property let currentspeed(byval ispeed)<BR> speed=ispeed<BR> end property<BR> <BR> public property get carcolor<BR> carColor=color<BR> end property<BR> <BR> public property let carcolor(byval strcolor)<BR> color=strcolor<BR> end property<BR> end class<BR> <BR>%&#062;<BR><BR>-------using the car class--------<BR>&#060;%@ Language=VBScript %&#062;<BR>&#060;%option explicit%&#062;<BR>&#060;!---#include file="carclass.asp"--&#062;<BR>&#060;!-- #include file="" --&#062;<BR><BR>&#060;%<BR> <BR> dim objCar<BR> dim objConn,objrs<BR> set objCar=New car<BR> <BR> objCar.currentspeed=60<BR> objCar.carcolor="red"<BR> Response.Write "Car speed is " &objCar.currentspeed<BR> Response.Write "car color is "&objCar.carcolor<BR> Set objConn = Server.createobject("ADODB.Connection") <BR> set objrs=Server.CreateObject("ADODB.Recordset")<BR> objConn.ConnectionString = "DSN=itmates;UID=sa;PWD=dhiraj;"<BR> objConn.Open<BR> "tryclass",objConn,,adLockOptimistic ,adCmdTable<BR><BR> Response.write "opened"<BR> objRS.addnew<BR> objRS("obj")=objCar &#060;----i get error here saying Provider error &#039;80020003&#039; Member not found.----&#062;<BR> objrs.update<BR> objrs.close<BR> Response.write "added"<BR> set objCar=Nothing<BR>%&#062;<BR>is there a mistake in the datatype i am using??or am i trying somehtng that cannot be accomplished using ASP??Please help!!<BR>thank you<BR>

  2. #2
    Join Date
    Dec 1969

    Default You mean VBScript object

    An ASP object would be an instance of one of the "builtin" ASP objects (e.g., Response, Request, etc.). And that won&#039;t work.<BR><BR>But, then, neither are you able to store instances of VBScript classes in a database. Or anyplace else, for that matter.<BR><BR>A VBScript class is *not* a true class. It&#039;s actually a "fake" that is implemented by a special internal collection in the VBScript engine.<BR><BR>You can&#039;t even do:<BR><BR>Set objCar = New Car<BR>Session("xyz") = objCar<BR><BR>Because an instance of a VBScript class does *NOT* implement the needed COM interfaces to make this possible.<BR><BR>Sorry about that, but the best you could do would be, perhaps, to "stringize" your Car instance with one method and "de-stringize" with another and then store the stringized form of the instance in the DB (or in the Session variable or to a file or...).<BR><BR>So something like:<BR><BR>Class car<BR>&nbsp; &nbsp; Private color, speed<BR><BR>&nbsp; &nbsp; ...<BR>&nbsp; &nbsp; Public Function SaveAsString( )<BR>&nbsp; &nbsp; &nbsp; &nbsp; SaveAs = color & "&#124&#124" & speed<BR>&nbsp; &nbsp; End Function<BR>&nbsp; &nbsp; Public Sub LoadFromString( str )<BR>&nbsp; &nbsp; &nbsp; &nbsp; Dim temp<BR>&nbsp; &nbsp; &nbsp; &nbsp; temp = Split( str, "&#124&#124" )<BR>&nbsp; &nbsp; &nbsp; &nbsp; color = temp(0)<BR>&nbsp; &nbsp; &nbsp; &nbsp; speed = CLng( temp(1) )<BR>&nbsp; &nbsp; End Sub<BR>&nbsp; &nbsp; ...<BR>End Class<BR>...<BR><BR>objRS.AddNew<BR>objRS("car") = objCar.SaveAsString( )<BR>...<BR><BR>%&#062;<BR><BR>And that&#039;s about the best you can do.<BR><BR>

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts