Visualizzazione dei risultati da 1 a 7 su 7

Discussione: connessione in file vb

  1. #1
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183

    connessione in file vb

    ciao a tutti
    ho un file con estensione vb che contiene delle classi

    vorrei creare dentro questo file una oledbconnection

    mi dite come crearle e dove posizionarla

    grazie
    victor
    ----------------------

  2. #2
    Allora io creo una costante pubblica

    Chiaramente devi importare
    codice:
    System.Data.OleDb
    Oppure puoi creare una proprietà della classe

    codice:
    Private Property CN as OleDb.OleDbConnection

  3. #3
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183

    grazie ma..

    ciao e grazie per la risposta
    continuo però ad avere errori

    ti posto la mia paginetta con estensione vb, questa pagina serve
    a fare l'upload

    se puoi inserisci dentro la pagina il codice per connettermi ad un db access

    grazie

    Imports System
    Imports System.web
    Imports System.web.UI
    Imports System.web.UI.WebControls
    Imports System.web.UI.HtmlControls
    Imports System.IO



    Public Class uploadFile: Inherits page
    protected withEvents CmdUpload as htmlInputbutton
    protected lblInfo as Label
    protected nome as Label
    protected canc as hyperlink
    protected fileInput as htmlInputFile
    protected path_img as htmlInputText


    private sub Page_load(sender as object, e as eventArgs) handles MyBase.load

    path_img.visible=false


    end sub


    Private Sub CmdUpload_ServerClick(sender as object, e as eventArgs) handles CmdUpload.ServerClick
    if fileInput.value = "" then
    lblInfo.text = "Specificare file"
    lblInfo.visible=true
    else
    'if fileInput.PostedFile.ContentType.StartsWith("image ") then



    dim file_path as string
    dim pre_file as string
    dim serverfilename as string

    'serverFilename = replace(path.getFileName (fileInput.postedFile.Filename)," ","_")
    serverFilename = path.getFileName(fileInput.postedFile.Filename).To String().Replace(" ", "_")
    'session("immagine_ok")=serverfilename

    response.cookies("primo_allegato").value=serverfil ename
    response.Cookies("primo_allegato").expires=datetim e.now.addmonths(1)



    dim dirc as new directoryInfo(server.mappath("/" & path_img.value))

    if dirc.exists then
    pre_file = path_img.value & serverfilename
    else
    pre_file = path_img.value & "/" & serverfilename
    end if
    file_path = Server.mappath(pre_file)
    fileinput.postedFile.saveAs(file_path)
    lblInfo.text = serverfilename
    nome.text=fileInput.value
    nome.text=serverfilename

    'lblinfo.text="[img] & session([/img]"
    if (serverfilename="") then
    CmdUpload.visible=true
    else
    CmdUpload.visible=false
    end if



    'catch err as exception
    'lblInfo.text = err.message
    'end try
    'else
    'lblInfo.text = "E' possibile caricare solo immagini"
    'lblinfo.visible=true
    end if

    end sub
    end Class
    victor
    ----------------------

  4. #4
    Fai cosi'

    codice:
    Imports System.Data
    Imports System.Data.OleDb
    
    Private CN As New OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;User ID=Admin;Data Source=" & "../Db/Data.mdb" & ";Mode=Share Deny None;Extended Properties='';Jet OLEDB:System database='';Jet OLEDB:Registry Path='';Jet OLEDB:Engine Type=5;Jet OLEDB:Database Locking Mode=1;Jet OLEDB:Global Partial Bulk Ops=2;Jet OLEDB:Global Bulk Transactions=1;Jet OLEDB:Create System Database=False;Jet OLEDB:Encrypt Database=False;Jet OLEDB:Don't Copy Locale on Compact=False;Jet OLEDB:Compact Without Replica Repair=False;Jet OLEDB:SFP=False")
    A questo punto ci lavori ...

    codice:
    Cn.Open
    'istruzione

  5. #5
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183
    questa è la pagina con la tua modifica

    codice:
    Imports System
    Imports System.web
    Imports System.web.UI
    Imports System.web.UI.WebControls
    Imports System.web.UI.HtmlControls
    Imports System.IO
    Imports System.Data
    Imports System.Data.OleDb
    
    Private CN As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.MapPath("rizzoli.mdb"))
    	
    
    
    
    Public Class uploadFile: Inherits page
    	protected withEvents CmdUpload as htmlInputbutton 
    	protected lblInfo as Label
    	protected nome as Label
    	protected canc as hyperlink
    	protected fileInput as htmlInputFile
    	protected path_img as htmlInputText
    
    
    	
    
    	
    		private sub Page_load(sender as object, e as eventArgs) handles MyBase.load
    	
    		path_img.visible=false
    	
    
    		end sub
    		
    	
    	Private Sub CmdUpload_ServerClick(sender as object, e as eventArgs) handles CmdUpload.ServerClick
    		if fileInput.value				= "" then
    			lblInfo.text				= "Specificare file"
    			lblInfo.visible=true
    		else
    			'if fileInput.PostedFile.ContentType.StartsWith("image")  then 
    				
    				
    					
    					dim file_path as string
    					dim pre_file as string
    					dim serverfilename as string
    
    					'serverFilename		= replace(path.getFileName (fileInput.postedFile.Filename)," ","_")
    					serverFilename = path.getFileName(fileInput.postedFile.Filename).ToString().Replace(" ", "_")
    					'session("immagine_ok")=serverfilename
    					
    					response.cookies("primo_allegato").value=serverfilename
    					response.Cookies("primo_allegato").expires=datetime.now.addmonths(1)
    					
    
    					
    					dim dirc as new directoryInfo(server.mappath("/" & path_img.value))
    					
    					if dirc.exists then
    						pre_file		= path_img.value & serverfilename
    					else
    						pre_file 		= path_img.value &  "/" & serverfilename
    					end if
    					file_path			= Server.mappath(pre_file)
    					fileinput.postedFile.saveAs(file_path)
    					lblInfo.text		= serverfilename
    					nome.text=fileInput.value
    					nome.text=serverfilename
    
    					'lblinfo.text="[img] &  session([/img]"
    					if (serverfilename="") then
    					CmdUpload.visible=true
    					else
    					CmdUpload.visible=false
    					end if
    						
    					
    					
    				'catch err as exception
    					'lblInfo.text		= err.message
    				'end try
    			'else
    				'lblInfo.text			= "E' possibile caricare solo immagini"
    				'lblinfo.visible=true
    			end if 
    			
    	end sub
    end Class

    ma mi da questo errore

    Compiler Error Message: BC30001: Statement is not valid in a namespace.

    Source Error:



    Line 8: Imports System.Data.OleDb
    Line 9:
    Line 10: Private CN As New OleDbConnection ("Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & server.MapPath("rizzoli.mdb"))
    Line 11:
    Line 12:

    grazie ancora
    victor
    ----------------------

  6. #6
    Gioia ma fai copia incolla delle info o qualcosa lo sai di NET???

    La variabile si mette dentro la classe mica nei namespace ...

    VVoVe: VVoVe: VVoVe:

  7. #7
    Utente di HTML.it
    Registrato dal
    Jun 2002
    Messaggi
    1,183
    grazie...mi sa che sono sulla giusta strada

    spero di potere contare ancora sul tuo aiuto
    victor
    ----------------------

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.