Author Topic: Connection with Ms Access  (Read 2497 times)

0 Members and 1 Guest are viewing this topic.

Ricky_76

  • Guest
Connection with Ms Access
« on: July 04, 2007, 02:22:15 AM »
Hi, I have some problem connecting access via vb.net!

I need 3 sub routines to GET, PUT and UPDATE records!

the GET routine works very well

    Public Sub db_Get(ByVal Tabella As String, ByVal Campo As String, ByRef Destinazione As String, Optional ByVal Filtro As String = "", Optional ByVal FiltroValue As String = "")
        Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & PercorsoDB & NomeDB
        Dim Cn As New OleDbConnection(ConnString)
        Cn.Open()
        'recupera i dati dal db
        Destinazione = ""
        Select Case Filtro
            Case ""
                Dim sql_MC As String = "select * from " & Tabella
                Dim cmd_MC As New OleDbCommand(sql_MC, Cn)
                Dim dr_MC As OleDbDataReader = cmd_MC.ExecuteReader
                Do While dr_MC.Read()
                    Destinazione = (dr_MC.Item(Campo))
                Loop
            Case Else
                Dim sql_MC As String = "select * from " & Tabella & " where " & Filtro & "=?"
                Dim cmd_MC As New OleDbCommand(sql_MC, Cn)
                cmd_MC.Parameters.AddWithValue(Filtro, FiltroValue)
                Dim dr_MC As OleDbDataReader = cmd_MC.ExecuteReader
                Do While dr_MC.Read()
                    Destinazione = (dr_MC.Item(Campo).ToString)
                Loop
        End Select
        Cn.Close()
    End Sub


the PUT routine works very well too

        Sub putDB(ByVal t As Margot.Contatto)
            If t.FTP.ToString = "" Then t.FTP = "NO"
            If t.Fornitore = "" Then t.Fornitore = "NO"
            If t.Cliente = "" Then t.Cliente = "NO"
            If t.RisorsaInterna = "" Then t.RisorsaInterna = "NO"
            If t.EsenteEPAP = "" Then t.EsenteEPAP = "NO"
            Dim PercorsoDB As String = "W:\00_00_00 - Programma_Gestione\File_Mdb\"
            Dim NomeDB = "Margot.mdb"
            Dim a As String = "', '"
            Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & PercorsoDB & NomeDB
            Dim Cn As New OleDbConnection(ConnString)
            Cn.Open()
            If t.Cognome <> "" Then
                Dim sql_MC As String = "INSERT INTO Tab_Contatti (Cognome, Nome, Societą, wIndirizzo, wCAP, wCittą, wProvincia, Accesso_FTP_Arcadia, FTP_User, FTP_Pwd,Cliente,Fornitore,EsenteEPAP,Risorsa_Interna, wMail) VALUES ('"
                sql_MC &= t.Cognome & a & t.Nome & a & t.Societą & a & t.wIndirizzo & a & t.wCap & a & t.wCittą & a & t.wProvincia & a & t.FTP & a & t.FTP_User & a & t.FTP_Pwd & a & t.Cliente & a & t.Fornitore & a & t.EsenteEPAP & a & t.RisorsaInterna & a & t.wMail & "')"
                Dim cmd_MC As New OleDbCommand(sql_MC, Cn)
                cmd_MC.ExecuteNonQuery()
            Else
                Dim sql_MC As String = "INSERT INTO Tab_Contatti (Cognome, Societą, wIndirizzo, wCAP, wCittą, wProvincia, Accesso_FTP_Arcadia, FTP_User, FTP_Pwd,Cliente,Fornitore,EsenteEPAP,Risorsa_Interna, wMail) VALUES ('"
                sql_MC &= t.Societą & a & t.Societą & a & t.wIndirizzo & a & t.wCap & a & t.wCittą & a & t.wProvincia & a & t.FTP & a & t.FTP_User & a & t.FTP_Pwd & a & t.Cliente & a & t.Fornitore & a & t.EsenteEPAP & a & t.RisorsaInterna & a & t.wMail & "')"
                Dim cmd_MC As New OleDbCommand(sql_MC, Cn)
                cmd_MC.ExecuteNonQuery()
            End If
            Cn.Close()
        End Sub



But I can't develop the UPDATE routine
Can someone help me?
tnx
/r

Fatty

  • Guest
Re: Connection with Ms Access
« Reply #1 on: July 04, 2007, 12:18:03 PM »
Hi
I am not tested this query but
logically you no needed to write separate
sub for that, use your PUT sub
Just change INSERT clause in SQLstring on
something like this

Code: [Select]
Dim sql_MC As String = "UPDATE Tab_Contatti SET Fornitore = "SomeValue" WHERE wMail = & a & "someone@gmail.com" & a &
SET next field = another one ETC

~'J'~

Ricky_76

  • Guest
Re: Connection with Ms Access
« Reply #2 on: July 04, 2007, 05:31:20 PM »
OK, tnx it works!!!!!!!

 :wink:


        Dim ConnString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source=" & PercorsoDB & NomeDB
        Dim Cn As New OleDbConnection(ConnString)
        Cn.Open()

        Dim sql_MC As String = "UPDATE Tab_Protocollo set Tipo_Missiva= 'HELLO' Where Codice_Commessa= '07_19_AI'"

        Dim cmd_MC As New OleDbCommand(sql_MC, Cn)
        cmd_MC.ExecuteNonQuery()
        Cn.Close()

Fatty

  • Guest
Re: Connection with Ms Access
« Reply #3 on: July 05, 2007, 04:14:51 AM »
Glad if that helps,
Btw, did you get my message?
Check you post please,

~'J'~

Ricky_76

  • Guest
Re: Connection with Ms Access
« Reply #4 on: July 06, 2007, 09:39:17 AM »
Hi Fatty,

Btw, did you get my message?
which one?? I read your response, that help me!

Check you post please,
??? ???

thank's again
/r

Fatty

  • Guest
Re: Connection with Ms Access
« Reply #5 on: July 06, 2007, 02:09:41 PM »
I've send a manual on your address
Hth

~'J'~