🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: free.it.visual-basic
Article #670

WebForm Query Inserimento con Oledb

#670
From: Maurizio
Date: Fri, 26 Aug 2005 13:03
53 lines
2787 bytes
uso VB.Net da vs2003 e da un WebForm non riesco a trovare il modo,
di creare un query di insert su un db Access
(l'help msdn cambia a seconda dell'argomento cercato) , il
modo di farlo a volte con Table altre con DataAdapter e
non capisco.
provate a darmi qualche consiglio.

grazie Maurizio

non ho creato a design time connection e/o dataadapter
nel modulo dichiaro Imports System.Data.OleDb

Private Sub Button6_Click(ByVal sender As System.Object, ByVal e As 
System.EventArgs) Handles Button6.Click
        Dim StrConn, myQuery, Path As String

        Path = Server.MapPath("\public")
        StrConn = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" + Path + 
"\db1.mdb;"

' in un libro trovo un esempio simile ma su Sql

        ' Create the Insert
        myQuery = "INSERT INTO Tabella1 (Cognome, Nome) " & "VALUES 
(pCognome, pNome)"

        Dim myAdapter As OleDbDataAdapter = New OleDbDataAdapter
        Dim cmd As OleDbCommand = New OleDbCommand(myQuery, myConn)
        Dim param As OleDbParameter
        Dim myInsert As New OleDbCommand(myQuery, myConn)

        param = New OleDbParameter("pCognome", OleDbType.Char)
        param.Value = "Cognome7"
        cmd.Parameters.Add(param)

        param = New OleDbParameter("pNome", OleDbType.Char)
        param.Value = "Nome7"
        cmd.Parameters.Add(param)

----> quando eseguue questa linea solleva eccezione :
----> l'operazione necessita di una query aggiornabile

        cmd.ExecuteNonQuery()

        myConn.Close()
    End Sub

--- ho provato anche ad usare InsertComamnd, ma l'errore e'
--- sempre l'operazione necessita di una query aggiornabile

       myAdapter.InsertCommand = myInsert
       mycmd.ExecuteNonQuery()
--/ 
Technical Details
Message-ID: <BqEPe.106074$fm.6970836@news4.tin.it>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!border2.nntp.ams.giganews.com!nntp.giganews.com!news-out.tin.it!news-in.tin.it!news4.tin.it.POSTED!not-for-mail

Show Full Headers
Complete Article Headers
X-Google-Thread: f94ee,26bf81789ef9091d,start
X-Google-Attributes: gidf94ee,public
X-Google-Language: ITALIAN,ASCII-7-bit
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!proxad.net!fr.ip.ndsoftware.net!border2.nntp.ams.giganews.com!nntp.giganews.com!news-out.tin.it!news-in.tin.it!news4.tin.it.POSTED!not-for-mail
From: "Maurizio" <maurizio@virgilio.it>
Newsgroups: free.it.visual-basic
Subject: WebForm Query Inserimento con Oledb
Lines: 55
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2180
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180
Message-ID: <BqEPe.106074$fm.6970836@news4.tin.it>
Date: Fri, 26 Aug 2005 13:03:29 GMT
NNTP-Posting-Host: 82.60.179.41
X-Complaints-To: "Please send abuse reports to abuse@tin.it and technical notifications to newsmaster@tin.it"
X-Trace: news4.tin.it 1125061409 82.60.179.41 (Fri, 26 Aug 2005 15:03:29 MET DST)
NNTP-Posting-Date: Fri, 26 Aug 2005 15:03:29 MET DST
Organization: TIN