Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Data Access Method
Message
 
À
31/10/2007 13:46:46
Information générale
Forum:
ASP.NET
Catégorie:
ADO.NET
Versions des environnements
Environment:
VB 8.0
OS:
Vista
Network:
Windows 2003 Server
Database:
Visual FoxPro
Divers
Thread ID:
01265411
Message ID:
01265779
Vues:
15
So I used the DataSet as you suggested and was able to populate it and bind it to controls on the form. Now, I want to save changes. I have the following code but is not working because no primary key is defined in the source table. How do I specify a Primary key in the DataAdapter/CommandBuilder?


Public Function SaveCust(ByVal ds As DataSet, ByVal cTable As String) As Boolean

Dim conn As OleDb.OleDbConnection = GetConnection()
Dim sql As String = "select * from " + cTable
Dim da As OleDb.OleDbDataAdapter = New OleDb.OleDbDataAdapter(sql, conn)
Dim cb As OleDb.OleDbCommandBuilder = New OleDb.OleDbCommandBuilder(da)
If ds.HasChanges Then
da.Update(ds, "Cust")
ds.AcceptChanges()
End If
da.Dispose()
conn.Close()
conn.Dispose()

Return True

End Function


>Patrick,
>
>Do NOT put the DataAccess in the Form. You need to organize your solution so that you have separate projects for DataAccess (and separate Business projects too). Then, have the DataAccess class get your data from the database and pass back a DataSet with the DataTable in it. Use that to bind to your controls. Since you say the layout is the same for all your tables, simply create a DataSet based on an .xsd of your table's layout.
>
>If you need more direction than this, just ask a few questions and we'll see if we can get you pointed in the right direction.
>
>~~Bonnie
>
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform