Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Funzionamento dell Update del DataAdapter
mercoledì 01 dicembre 2004 - 16.20
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
ysdemarc
Profilo
| Expert
587
messaggi | Data Invio:
mer 1 dic 2004 - 16:20
Ho fatto una classe che alla fine fa quello che fanno le righe di codice sotto riportate.
nella tabella vengono estratte solo 3 righe di esse ne modifico 2. Le righe vengono lette tranquillamente senza problemi.Il metodo Update del dataAdapter mi restituisce il numero di righe modificate e in output ho: aggiornati: 2.
Il tutto senza errori. vado a vedere nel db e le righe sono tale e quali prima di aggiornarle... non è successo niente... perchè.. qualcuno mi può aiutare? sto uscendo pazzo...
grazie a tutti
ps: per comodità di esecuzione il codice sottoriportato è in vb.net la classe in c#.
Dim cn As New SqlConnection
cn.ConnectionString = "Data Source=mydatasource; User ID=myid;Password=mypass;Initial Catalog=mycatalog"
Dim Sql As String = "SELECT * from prova where contatore < 41"
cn)
cn.Open()
Dim cm As New SqlCommand(Sql, cn)
Dim da As New SqlDataAdapter
da.UpdateCommand = cm
da.DeleteCommand = cm
da.InsertCommand = cm
da.SelectCommand = cm
Dim ds As New DataSet
da.FillSchema(ds, SchemaType.Source)
da.Fill(ds)
Dim dtc As DataTableCollection = ds.Tables
Dim dt As DataTable
Dim r As DataRow
For x As Int32 = 0 To dtc.Count - 1 <--- dtc.Count è uguale a 1
dt = dtc(x)
For i As Int32 = 0 To dt.Rows.Count - 1 <---- dt.Rows.Count è uguale a 3
r = dt.Rows(i)
If i > 0 Then <---- la prima non la modifico
r("campo") = r("campo") & "***"
End If
Next
Next
Dim res As Int32 = da.Update(ds) <--- restituisce 2 ma non è successo niente
cn.Close()
Console.WriteLine("aggiornati: " & res)
Brainkiller
Profilo
| Guru
7.999
messaggi | Data Invio:
lun 6 dic 2004 - 01:17
Ciao,
prova a lanciare il SQL Profiler e vedi un po' se durante l'update succede qualcosa nel DB.
E'un utile strumento per fare il debug il SQL Profiler.
ciao
david
ysdemarc
Profilo
| Expert
587
messaggi | Data Invio:
lun 6 dic 2004 - 12:22
Sbagliavo nell'assegnazione dell'oggetto SqlCommand ai relativi metodi di aggiornamento del DataAdapter.
Ho risolto facendo le assegnazioni in questo modo:
SqlCommandBuilder cb = new SqlCommandBuilder(da);
cb.RefreshSchema();
da.DeleteCommand = cb.GetDeleteCommand();
da.InsertCommand = cb.GetInsertCommand();
da.UpdateCommand = cb.GetUpdateCommand();
grazie, Ciao!
Torna su
Stanze Forum
Elenco Threads
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 !