ADO.Stream and ADO.RecordSet 
Author Message
 ADO.Stream and ADO.RecordSet

What's wrong in this code from an ASPX page?
The example fron VFP 7 works fine.

* C# code
private void Button1_Click(object sender, System.EventArgs e){
 ADODB.Connection oConn = new ADODB.Connection();
 ADODB.Recordset oRS = new ADODB.Recordset();
 ADODB.Stream oStream = new ADODB.StreamClass();
 oConn.Open("Provider=SQLOLEDB;Data Source=SERVER;Initial
Catalog=stock;Integrated Security=SSPI;", "sa", "", -1);
 oRS.Open("SELECT last_name, photo FROM users", oConn,
ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly,
1);
 oStream.Type = ADODB.StreamTypeEnum.adTypeBinary;
 oStream.Open("select photo from
users",ADODB.ConnectModeEnum.adModeRead,ADODB.StreamOpenOptionsEnum.adOpenSt
reamFromRecord,"sa","");
 while (oRS.EOF != true)
     {
  String sname = txtname.Text;
  if (oRS.Fields("last_name")=sname) // errors from here
     {
   oStream.Write(oRS.Fields("Photo"));
   String lcimage = "image.jpg";
   oStream.SaveToFile(lcimage,2);
   image.ImageURL="image.jpg";
     }
   else{
   oRS.MoveNext;
   }

* VFP code
LOCAL lcConnStr, lcSQL, loConnection, lcImageName, loRecordset, ;
 loADOStream

lcConnStr = "Provider=SQLOLEDB;"+;
 "Data Source=SERVER;"+;
 "Initial Catalog=stock;"+;
 "UID=SA;Pwd=''"
lcSQL = "SELECT * FROM users"
loConnection = CREATEOBJECT("ADODB.Connection")
loRecordset = CREATEOBJECT("ADODB.Recordset")
loADOStream = CREATEOBJECT("ADODB.Stream")
loConnection.OPEN(lcConnStr)
loRecordset.Open(lcSQL, loConnection,2,3)
loADOStream.TYPE = 1
loADOStream.OPEN
DO WHILE !loRecordset.EOF
 IF loRecordset.Fields("last_name").Value =thisform.cboName.DisplayValue
  loADOStream.Write(loRecordset.Fields("Photo"))
  lcImagename = "image.JPG"
  loADOStream.SaveToFile(lcImageName,2)
  IF thisform.image1.Visible = .F.
   thisform.image1.Visible = .T.
  ENDIF
  thisform.image1.Picture = "image.jpg"
  EXIT
 ELSE
  loRecordset.movenext
 ENDIF
ENDDO

loRecordset.Close
loConnection.Close
loADOStream.close    }



Sun, 22 Aug 2004 18:33:44 GMT  
 ADO.Stream and ADO.RecordSet
Sorin,

    The line should be:

if (oRS.Fields("last_name") == sname)

    In C#, you need to use == for comparison, not =, which is an assignment
operator.

    Hope this helps.

--
               - Nicholas Paldino [.NET MVP]


Quote:
> What's wrong in this code from an ASPX page?
> The example fron VFP 7 works fine.

> * C# code
> private void Button1_Click(object sender, System.EventArgs e){
>  ADODB.Connection oConn = new ADODB.Connection();
>  ADODB.Recordset oRS = new ADODB.Recordset();
>  ADODB.Stream oStream = new ADODB.StreamClass();
>  oConn.Open("Provider=SQLOLEDB;Data Source=SERVER;Initial
> Catalog=stock;Integrated Security=SSPI;", "sa", "", -1);
>  oRS.Open("SELECT last_name, photo FROM users", oConn,
> ADODB.CursorTypeEnum.adOpenForwardOnly, ADODB.LockTypeEnum.adLockReadOnly,
> 1);
>  oStream.Type = ADODB.StreamTypeEnum.adTypeBinary;
>  oStream.Open("select photo from

users",ADODB.ConnectModeEnum.adModeRead,ADODB.StreamOpenOptionsEnum.adOpenSt

- Show quoted text -

Quote:
> reamFromRecord,"sa","");
>  while (oRS.EOF != true)
>      {
>   String sname = txtname.Text;
>   if (oRS.Fields("last_name")=sname) // errors from here
>      {
>    oStream.Write(oRS.Fields("Photo"));
>    String lcimage = "image.jpg";
>    oStream.SaveToFile(lcimage,2);
>    image.ImageURL="image.jpg";
>      }
>    else{
>    oRS.MoveNext;
>    }

> * VFP code
> LOCAL lcConnStr, lcSQL, loConnection, lcImageName, loRecordset, ;
>  loADOStream

> lcConnStr = "Provider=SQLOLEDB;"+;
>  "Data Source=SERVER;"+;
>  "Initial Catalog=stock;"+;
>  "UID=SA;Pwd=''"
> lcSQL = "SELECT * FROM users"
> loConnection = CREATEOBJECT("ADODB.Connection")
> loRecordset = CREATEOBJECT("ADODB.Recordset")
> loADOStream = CREATEOBJECT("ADODB.Stream")
> loConnection.OPEN(lcConnStr)
> loRecordset.Open(lcSQL, loConnection,2,3)
> loADOStream.TYPE = 1
> loADOStream.OPEN
> DO WHILE !loRecordset.EOF
>  IF loRecordset.Fields("last_name").Value =thisform.cboName.DisplayValue
>   loADOStream.Write(loRecordset.Fields("Photo"))
>   lcImagename = "image.JPG"
>   loADOStream.SaveToFile(lcImageName,2)
>   IF thisform.image1.Visible = .F.
>    thisform.image1.Visible = .T.
>   ENDIF
>   thisform.image1.Picture = "image.jpg"
>   EXIT
>  ELSE
>   loRecordset.movenext
>  ENDIF
> ENDDO

> loRecordset.Close
> loConnection.Close
> loADOStream.close    }



Sun, 22 Aug 2004 23:32:59 GMT  
 ADO.Stream and ADO.RecordSet
My problem is oStream.Open() because it needs parameters wich I don't know.



Quote:
> Sorin,

>     The line should be:

> if (oRS.Fields("last_name") == sname)

>     In C#, you need to use == for comparison, not =, which is an
assignment
> operator.

>     Hope this helps.

> --
>                - Nicholas Paldino [.NET MVP]



> > What's wrong in this code from an ASPX page?
> > The example fron VFP 7 works fine.

> > * C# code
> > private void Button1_Click(object sender, System.EventArgs e){
> >  ADODB.Connection oConn = new ADODB.Connection();
> >  ADODB.Recordset oRS = new ADODB.Recordset();
> >  ADODB.Stream oStream = new ADODB.StreamClass();
> >  oConn.Open("Provider=SQLOLEDB;Data Source=SERVER;Initial
> > Catalog=stock;Integrated Security=SSPI;", "sa", "", -1);
> >  oRS.Open("SELECT last_name, photo FROM users", oConn,
> > ADODB.CursorTypeEnum.adOpenForwardOnly,

ADODB.LockTypeEnum.adLockReadOnly,
Quote:
> > 1);
> >  oStream.Type = ADODB.StreamTypeEnum.adTypeBinary;
> >  oStream.Open("select photo from

users",ADODB.ConnectModeEnum.adModeRead,ADODB.StreamOpenOptionsEnum.adOpenSt

- Show quoted text -

Quote:
> > reamFromRecord,"sa","");
> >  while (oRS.EOF != true)
> >      {
> >   String sname = txtname.Text;
> >   if (oRS.Fields("last_name")=sname) // errors from here
> >      {
> >    oStream.Write(oRS.Fields("Photo"));
> >    String lcimage = "image.jpg";
> >    oStream.SaveToFile(lcimage,2);
> >    image.ImageURL="image.jpg";
> >      }
> >    else{
> >    oRS.MoveNext;
> >    }

> > * VFP code
> > LOCAL lcConnStr, lcSQL, loConnection, lcImageName, loRecordset, ;
> >  loADOStream

> > lcConnStr = "Provider=SQLOLEDB;"+;
> >  "Data Source=SERVER;"+;
> >  "Initial Catalog=stock;"+;
> >  "UID=SA;Pwd=''"
> > lcSQL = "SELECT * FROM users"
> > loConnection = CREATEOBJECT("ADODB.Connection")
> > loRecordset = CREATEOBJECT("ADODB.Recordset")
> > loADOStream = CREATEOBJECT("ADODB.Stream")
> > loConnection.OPEN(lcConnStr)
> > loRecordset.Open(lcSQL, loConnection,2,3)
> > loADOStream.TYPE = 1
> > loADOStream.OPEN
> > DO WHILE !loRecordset.EOF
> >  IF loRecordset.Fields("last_name").Value =thisform.cboName.DisplayValue
> >   loADOStream.Write(loRecordset.Fields("Photo"))
> >   lcImagename = "image.JPG"
> >   loADOStream.SaveToFile(lcImageName,2)
> >   IF thisform.image1.Visible = .F.
> >    thisform.image1.Visible = .T.
> >   ENDIF
> >   thisform.image1.Picture = "image.jpg"
> >   EXIT
> >  ELSE
> >   loRecordset.movenext
> >  ENDIF
> > ENDDO

> > loRecordset.Close
> > loConnection.Close
> > loADOStream.close    }



Mon, 23 Aug 2004 13:27:02 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. ADO Recordset Save to Stream, adPersistXML

2. How do open Recordset from XML stream object use ADO in VC6

3. How to open Recordset from XML stream use Ado in VC6

4. Speed of ADO Recordset vs ADO Command in VC

5. Problem with ADO recordsets of recordsets under MTS

6. ADO Stream

7. Help with ADO Stream

8. ADO Stream

9. ADO bindings together with recordset Filtering

10. Problems getting values from ADO Recordset

11. Exception thrown when opening ADO recordset

12. Using ADO recordset binding to retrieve BLOBs

 

 
Powered by phpBB® Forum Software