Problemi con indirizzi email

Ciao a tutti, sto avendo problemi a recuperare con una query gli indirizzi email presenti in un db sql2008R2.

il codice che uso il seguente (ho provato con altri campi e funziona, quindi credo sia un problema di @ o cose simili):

If db.Connect Then
  dim stringaSQL as string
  Dim ps As MSSQLServerPreparedStatement
  Dim rs as RecordSet
  
  ps = db.Prepare("select EMAGENI1, EMAGENI2 from ANA_STUD where CODSTUDE= ?")
  
  ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
  ps.Bind(0, CodAlunno)
  rs = ps.SQLSelect
  
  if rs <> Nil Then
    While Not rs.EOF
      MsgBox(rs.IdxField(1).StringValue)
      
      if rs.IdxField(1).StringValue.Trim.Len > 0  and rs.IdxField(2).StringValue.Trim.Len > 0 then
        TxtEmail.Text=rs.IdxField(1).StringValue.Trim+";"+rs.IdxField(2).StringValue.Trim
      end if
      
      if rs.IdxField(1).StringValue.Trim.Len > 0  and rs.IdxField(2).StringValue.Trim.Len = 0 then
        TxtEmail.Text=rs.IdxField(1).StringValue.Trim
      end if
      
      if rs.IdxField(1).StringValue.Trim.Len = 0  and rs.IdxField(2).StringValue.Trim.Len > 0 then
        TxtEmail.Text=rs.IdxField(2).StringValue.Trim
      end if
      rs.MoveNext
    Wend
    rs.Close
  end if
Else
  MsgBox("Connection error:" + db.ErrorMessage)
End If

il msgbox torna sempre vuoto, ma il recordset non null altrimenti non lo visualizzerei, secondo me legato al contenuto del campo…

mi date una mano? grz

ciro

Invece di usare msgbox usa il debugger mettono un breakpoint e verificando il contenuto del record set (se ad esempio EOF)
Puoi mettere due variabili d’appoggio dim txt1, txt2 as string
caricarne il valore dal record set
txt1=rs.idxField(1).stringvalue.trim
txt2=rs.idxField(2).stringValue.trim

Puoi semplificare il tuo codice definiendo una variabile vTxt() as string
nel loop
redim vTxt(-1)
for i as integer=1 to 2
if rs.idxField(i).stringValue.trim<>"" then vTxt.append if rs.idxField(i).stringValue.trim
next
txtEmail.text=join(vTxt, “;”)

ho provato anche con il debugger antonio, il recordset nn nil ma i due rs.idxField(1).stringvalue.trim sono blank

prova a leggere il campo con:
dim m as memoryblock=rs.idxField(1).nativeValue
break
e dimmi il contenuto (almeno la dimensione ovvero size) di m nel momento del break

allora antonio, il problema serio, in pratica tutte le query che eseguo dalla stessa dialog (anche se in posti diversi: eventi o metodi) non riportano valori,
questo il codice del metodo della dialog, trovi accanto i miei commenti;

//recuperiamo il nominativo alunno per la descrizione del pagamento
Dim db As New MSSQLServerDatabase

db.Host =FiveStars_Scuola.host // or just the IP if using the default instance
db.DatabaseName = FiveStars_Scuola.dbnm
db.UserName = FiveStars_Scuola.user  // or "Domain\\UserID for trusted domain accounts
db.Password = FiveStars_Scuola.pass

Dim nominativo as string
If db.Connect Then
  dim stringaSQL as string
  Dim ps As MSSQLServerPreparedStatement
  Dim rs as RecordSet
  
  ps = db.Prepare("select COGSTUDE, NOMSTUDE from ANA_STUD where CODSTUDE= ?")  <<<<<< QUI FUNZIONA >>>>>>
  ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_STRING)
  ps.Bind(0, CodAlunno)
  rs = ps.SQLSelect
  
  if rs <> Nil Then
    While Not rs.EOF
      nominativo=rs.IdxField(1).StringValue.Trim+" "+rs.IdxField(2).StringValue.Trim
      rs.MoveNext
    Wend
    rs.Close
  end if
  
  //dati da passare a stripe
  dim datas() as string
  
  datas.Append "amount="            + EncodeURLComponent(TxtRicarica.Text+"00")
  datas.Append "currency="          + EncodeURLComponent("eur")
  datas.Append "description="       + EncodeURLComponent("Ricarica Fivestars School "+CodAlunno.trim+"-"+nominativo.Trim)
  datas.Append "source[object]="    + EncodeURLComponent("card")
  datas.Append "source[number]="    + EncodeURLComponent(TxtCardNumber.Text)
  datas.Append "source[exp_month]=" + EncodeURLComponent(SpMese.Text)
  datas.Append "source[exp_year]="  + EncodeURLComponent(SpAnno.Text)
  datas.Append "source[cvc]="       + EncodeURLComponent(TxtCvc.Text)
  
  
  dim c as new CURLSMBS
  
  c.OptionVerbose = true
  c.OptionURL = "https://api.stripe.com/v1/charges"
  c.OptionUsername = FiveStars_Scuola.skey
  
  c.OptionPost = true
  c.OptionPostFields = Join(datas, "&")
  c.OptionSSLVersion = c.kSSLVersionTLSv12
  
  dim e as integer = c.Perform
  
  DebugTextArea.Text = c.DebugData
  ResultTextArea.Text = c.OutputData
  
  //processiamo il ritorno di stripe,  un JSON
  Dim js As New JSONItem(ResultTextArea.Text) ' assume Data is the raw JSON string
  'MsgBox (JSONinput.ToString)
  
  Dim id,status As Variant
  id = js.Lookup("id", "Data not found")
  status = js.Lookup("status", "Data not found")
  
  if status <> "Data not found" then
    //tutto ok
    if status= "succeeded" then
      MessaggioDialog1.ApriMessaggio("Il pagamento  stato correttamente inoltrato!")
      //genero il file csv
      Dim f As FolderItem
      dim filestream as TextOutputStream
      Dim nomefile as string
      nomefile = "stripe_payment_"+id+".txt"
      //creo il file se non esiste
      f = GetFolderItem(nomefile)
      If f <> Nil Then
        f.Delete
      end if
      fileStream = TextOutputStream.Create(f)
      Dim d as new date
      fileStream.WriteLine(CodAlunno+";"+TxtRicarica.Text+";"+d.Year.ToText+if(d.Month<10,"0"+d.Month.ToText,d.Month.ToText)+if(d.Day<10,"0"+d.Day.ToText,d.Day.ToText))
      fileStream.Close
      //scrivo nel log la transazione
      dim datainvio as new date
      // recuperiamo il progressivo
      dim newprog as string
      dim maxprog as integer
      maxprog=0
      stringaSQL="SELECT PROGTRANS FROM LOG_TRAN order by PROGTRANS"
      ps = db.Prepare(stringaSQL)
      rs=ps.SQLSelect
      if rs <> Nil Then   <<<<<< QUI rs E' SEMPRE NIL >>>>>>
        While Not rs.EOF
          msgbox(rs.IdxField(1).StringValue)
          maxprog=rs.IdxField(1).IntegerValue
          rs.MoveNext
        Wend
        rs.Close
      End If
      maxprog=maxprog+1
      newprog="0000000000"+str(maxprog)
      newprog=newprog.Right(10)
      // procediamo all'inserimento
      stringaSQL="insert into LOG_TRAN (PROGTRANS,DATATRANS,CODSTUDE,TIPSTUDE,COGSTUDE,NOMSTUDE,CODANNSC,CODSCUOL,CLASTUDE,SEZSTUDE,EMAGENI1,EMAGENI2,IMPOTRANS,IDTRANS) VALUES ("
      stringaSQL=stringaSQL+"'"+newprog+"',"
      stringaSQL=stringaSQL+"'"+datainvio.Year.ToText+right("00"+datainvio.Month.ToText,2)+right("00"+datainvio.Day.ToText,2)+"',"
      stringaSQL=stringaSQL+"'"+CodAlunno+"',"
      stringaSQL=stringaSQL+"'A',"
      stringaSQL=stringaSQL+"'test',"
      stringaSQL=stringaSQL+"'test',"
      stringaSQL=stringaSQL+"'"+Login_Page.SpAnnoSco.Text+"',"
      stringaSQL=stringaSQL+"'scuola',"
      stringaSQL=stringaSQL+"'1',"
      stringaSQL=stringaSQL+"'s',"
      stringaSQL=stringaSQL+"'"+TxtEmail.Text+"',"
      stringaSQL=stringaSQL+"'"+TxtEmail.Text+"',"
      stringaSQL=stringaSQL+"'"+TxtRicarica1.Text+","+TxtRicarica2.Text+"',"
      stringaSQL=stringaSQL+"'"+id+"')"
      break
      ps = db.Prepare(stringaSQL)
      
      ps.SQLExecute
      //invio la mail
      //smtp diretto
      
      Dim SMTPsrv,SMTPuser,SMTPpwd,SMTPport as string
      stringaSQL="select smtpsrv,smtpuser,smtppwd,smtpport from par_comu where primkey='NCS' "
      ps = db.Prepare(stringaSQL)
      rs=ps.SQLSelect
      if rs <> Nil Then
        While Not rs.EOF
          SMTPsrv=rs.IdxField(1).StringValue
          SMTPuser=rs.IdxField(2).StringValue
          SMTPpwd=rs.IdxField(3).StringValue
          SMTPport=rs.IdxField(4).StringValue
          rs.MoveNext
        Wend
        rs.Close
      End If
      dim smtp as new SMTPSecureSocket
      smtp.Address = SMTPsrv.Trim
      smtp.Secure = False
      smtp.Port = SMTPport.Trim.Val
      smtp.ConnectionType = 1
      smtp.Username = SMTPuser.Trim
      smtp.Password = SMTPpwd.Trim
      Dim mail As New EmailMessage
      mail.FromAddress = "c.marciano@ncssrl.it"
      mail.AddRecipient(TxtEmail.Text)
      mail.Subject = "Ricarica FiveStars School"
      
      dim lines() as string
      lines.Append "Gentile Utente,"
      lines.Append "con la presente Le comunichiamo la presa in carico della ricarica di  "+TxtRicarica.Text+" relativa all'alunno "+nominativo
      lines.Append "Distinti Saluti"
      mail.BodyPlainText = Join(lines, EndOfLine)
      break
      smtp.Messages.Append(mail)
      smtp.SendMail()
    end if
  else
    //vediamo l'errore
    Dim jserror As JSONItem = js.Value("error")
    Dim error As Variant
    error = jserror.Lookup("message", "Data not found")
    'MsgBox(status+" - "+error)
    if error <> "Data not found" then
      if error= "Could not find payment information" then
        MessaggioDialog1.ApriMessaggio("Attenzione, verificare i dati della carta!")
      end if
      if error= "Your card number is incorrect." or error= "The card number is not a valid credit card number." then
        MessaggioDialog1.ApriMessaggio("Attenzione, il numero di carta non  corretto!")
      end if
      if error= "Your card's expiration year is invalid." then
        MessaggioDialog1.ApriMessaggio("Attenzione, l'anno scadenza carta non  corretto!")
      end if
      if error= "Your card's expiration month is invalid." then
        MessaggioDialog1.ApriMessaggio("Attenzione, il mese scadenza carta non  corretto!")
      end if
      if error= "Your card's security code is invalid." then
        MessaggioDialog1.ApriMessaggio("Attenzione, il codice di sicurezza carta non  corretto!")
      end if
    end if
  end if
  //azzeriamo tutto il json
  js.Clear
Else
  MsgBox("Connection error:" + db.ErrorMessage)
End If

Hai provato a non usare il preparedStatement per la query che non funziona?
una query senza parametri potrebbe avere problemi.
In alternativa potresti aggiungere un where 1=?
bindType integer
bindValue=1

Strano che poi costruisci una stringa sql invece di utilizzare un vero prepared statement per l’inserimento

provato Antonio, rs continua ad essere null

      stringaSQL="SELECT PROGTRANS FROM LOG_TRAN where 1=? order by PROGTRANS"
      ps = db.Prepare(stringaSQL)
      ps.BindType(0, MSSQLServerPreparedStatement.MSSQLSERVER_TYPE_INT)
      ps.Bind(0, 1)
      rs=ps.SQLSelect
      if rs <> Nil Then
        While Not rs.EOF
          msgbox(rs.IdxField(1).StringValue)
          maxprog=rs.IdxField(1).IntegerValue
          rs.MoveNext
        Wend
        rs.Close
      End If

tra l’altro fallisce anche la insert successiva, pur bypassando il discorso progressivo (recuperato tramite select di cui sopra). in debug la sintassi sql corretta, infatti lanciandola direttamente in sql inserisce il record.

      dim stringaSQL as string
      stringaSQL="insert into LOG_TRAN (PROGTRANS,DATATRANS,CODSTUDE,TIPSTUDE,COGSTUDE,NOMSTUDE,CODANNSC,CODSCUOL,CLASTUDE,SEZSTUDE,EMAGENI1,EMAGENI2,IMPOTRANS,IDTRANS) VALUES ("
      stringaSQL=stringaSQL+"'"+newprog+"',"
      stringaSQL=stringaSQL+"'"+datainvio.Year.ToText+right("00"+datainvio.Month.ToText,2)+right("00"+datainvio.Day.ToText,2)+"',"
      stringaSQL=stringaSQL+"'"+CodAlunno+"',"
      stringaSQL=stringaSQL+"'A',"
      stringaSQL=stringaSQL+"'test',"
      stringaSQL=stringaSQL+"'test',"
      stringaSQL=stringaSQL+"'"+Login_Page.SpAnnoSco.Text+"',"
      stringaSQL=stringaSQL+"'scuola',"
      stringaSQL=stringaSQL+"'1',"
      stringaSQL=stringaSQL+"'s',"
      stringaSQL=stringaSQL+"'"+TxtEmail.Text+"',"
      stringaSQL=stringaSQL+"'"+TxtEmail.Text+"',"
      stringaSQL=stringaSQL+"'"+TxtRicarica1.Text+","+TxtRicarica2.Text+"',"
      stringaSQL=stringaSQL+"'"+id+"')"
      break
      ps = db.Prepare(stringaSQL)
      
      ps.SQLExecute

a questo punto forse nei metodi e/o dialog c’ qualcosa di strano…

[quote=342974:@Antonio Rinaldi]dim m as memoryblock=rs.idxField(1).nativeValue
break[/quote]

Invece, in merito a quest’altro problema, seguendo il tuo suggerimento ottengo:

LittleEndian True
Size 200

ho risolto! scusate il disturbo ma c’era una stringa che puntava ad un vecchio db nascosta da qualche parte…

Ecco trovato l’arcano mistero!