OleDbDataAdapter datagridview update

sabato 12 marzo 2011 - 15.29
Tag Elenco Tags  VB.NET  |  Visual Studio 2008  |  Access (.mdb)

caniggiaroby Profilo | Newbie

Ciao a tutti,

ho il problema che non riesco a salvare i dati da una datagridview nel db access.

Ho un db semplice con una tabella con 2 campi id e descrizione, ora da form scelgo il db e mi vedo ida ti sulla grid.

fin qua tutto bene.

ho un modulo

Imports System.Data
Imports System.Data.OleDb

Module Module1

Public oDataSet As DataSet
Public oQuery As String
Public oDad As OleDbDataAdapter
Public oCbuild As OleDbCommandBuilder
Public oDbCommand As New OleDbCommand
Public bs As BindingSource
Public selCmd As OleDbCommand
Public updCmd As OleDbCommand
Public insCmd As OleDbCommand
Public delCmd As OleDbCommand

End Module

sulla classe del form

Private Sub btnVisualizza_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnVisualizza.Click

Campi = CampiSelezionati()
Tabella = lstTabelle.SelectedItem.ToString

oQuery = "Select " & Campi & " from " & Tabella

oDbCommand.Connection = oCn
oDbCommand.CommandText = oQuery

oDad = New OleDbDataAdapter(oDbCommand)

oCbuild = New OleDb.OleDbCommandBuilder(oDad)

oDad.DeleteCommand() = oCbuild.GetDeleteCommand
oDad.InsertCommand() = oCbuild.GetInsertCommand
oDad.UpdateCommand() = oCbuild.GetUpdateCommand

oDataSet = New DataSet("dt")
oDad.Fill(oDataSet, "dt")

bs = New BindingSource
bs.DataSource = oDataSet
bs.DataMember = "dt"

Griglia.DataSource = oDataSet
Griglia.DataMember = "dt"

End Sub

e quando salvo

Private Sub Button1_Click_1(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

Select Case Trim(My.Forms.ExtractWeb.oTitoloColonna.ToLower)
Case "descrizione"

My.Forms.ExtractWeb.Griglia.Rows.Item(My.Forms.ExtractWeb.oIndiceRiga).Cells.Item(My.Forms.ExtractWeb.oIndiceColonna).Value() = Me.HtmlSource.Text

Case Else

My.Forms.ExtractWeb.Griglia.Rows.Item(My.Forms.ExtractWeb.oIndiceRiga).Cells.Item(My.Forms.ExtractWeb.oIndiceColonna).Value() = StripTags(Me.HtmlSource.Text)

End Select

oCbuild = New OleDb.OleDbCommandBuilder(oDad)

Dim a As String = oDad.Fill(oDataSet)

oCbuild.GetUpdateCommand()
a = oDad.Update(oDataSet)

a = "1"
''ExtractWeb.oDad.InsertCommand = ExtractWeb.oCbuild.GetInsertCommand
''ExtractWeb.oDad.DeleteCommand = ExtractWeb.oCbuild.GetDeleteCommand
''ExtractWeb.oDad.UpdateCommand = ExtractWeb.oCbuild.GetUpdateCommand

'oDad.AcceptChangesDuringFill = True
'oDad.AcceptChangesDuringUpdate = True

'oDataSet.EndInit()

'oDad.Update(oDataSet)

'oDataSet.AcceptChanges()

Catch ex As Exception

End Try

End Sub

PERCHE' NON VA?
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?

Dopo esserti registrato potrai chiedere
aiuto sul nostro Forum oppure aiutare gli altri

Consulta le Stanze disponibili.

Registrati ora !
Copyright © dotNetHell.it 2002-2017
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5