Visualizzazione dei risultati da 1 a 3 su 3

Discussione: [VB.NET]Datareader

  1. #1
    Utente di HTML.it L'avatar di Aki
    Registrato dal
    Dec 2002
    Messaggi
    2,206

    [VB.NET]Datareader

    ho 'sto codice:
    codice:
    Sub Page_Load()
    		Dim str as string = "Server=xxx.xxx.xxx.xxx;Database=CURRICULUM;User ID=xxx;pwd=xxx"
    		Dim conn as new sqlconnection(str)
    		conn.open()
    		Dim sql as string = "SELECT ID_USER, DATA_CREAZIONE, NOME FROM ANAGRAFICA WHERE ISDEL = 0 "
    		If Session("INFO") = "" then
    		else
    			sql &= " AND NOME LIKE " + Session("INFO") + ""
    		end if
    		If Session("CF") = "" then
    		else
    			sql &= " AND FISCALE = " + Session("CF") + ""
    		end if
    		If Session("DATA_INI") = "Scegli/Scegli/Scegli" then
    		else
    			sql &= " AND DATA_CREAZIONE BETWEEN = '" + Session("DATA_INI") + "' AND '" + Session("DATA_FIN") + "'"
    		end if	
    		sql &= " ORDER BY DATA_CREAZIONE DESC"
    		response.Write(sql)
    	Dim cmd as new sqlcommand(sql, conn)
    		Dim dr as sqlDatareader = cmd.ExecuteReader()
    		While dr.read()
    	
    			response.Write("<table border='1' width='70%'><tr><td width='5%'>" + CStr(dr.Item("ID_USER")) + "</td>")
    			response.Write("<td width='15%'>" + dr.Item("DATA_CREAZIONE") + "</td>")
    			response.Write("<td width='50%'>" + dr.item("NOME") + "</td>")
    			If Session("edi") = 1 then
    				response.Write("<td>[img]../img/edit.gif[/img]</td>")
    			end if
    			if session("del") = 1 then
    				response.Write("<td><a href='delete.aspx?id=" + CStr(dr.Item("ID_USER")) + "&nm=" + CStr(dr.Item("NOME")) + "' target='topFrame'>[img]../img/delete.gif[/img]</td>")
    			end if
    			response.Write("</tr></table>")
    		
    	
    		end while
    		dr.close()
    		conn.close()
    	end sub
    apparentemente giusto ma mi dà 'sto errore:
    Server Error in '/wcv' Application.
    --------------------------------------------------------------------------------

    Line 1: Incorrect syntax near '='.
    Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code.

    Exception Details: System.Data.SqlClient.SqlException: Line 1: Incorrect syntax near '='.

    Source Error:


    Line 23: response.Write(sql)
    Line 24: Dim cmd as new sqlcommand(sql, conn)
    Line 25: Dim dr as sqlDatareader = cmd.ExecuteReader()
    Line 26: While dr.read()
    Line 27:


    Source File: D:\Wcv\Admin\reader.aspx Line: 25

  2. #2

    Re: [VB.NET]Datareader

    BETWEEN non vuole l'=, solo i due valori separatida AND
    codice:
    ...
    		If Session("DATA_INI") = "Scegli/Scegli/Scegli" then
    		else
    			sql &= " AND DATA_CREAZIONE BETWEEN '" + Session("DATA_INI") + "' AND '" + Session("DATA_FIN") + "'"
    		end if

  3. #3
    Se non funziona ancora dopo la correzione di DeBe99 fai un bel response.write di sql così vediamo cosa c'è dentro!
    Ciao
    Kalman
    Kalman

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.