|
-
Jun 16th, 2005, 05:26 PM
#1
DataAdapter and using .Update to save dataset
VB Code:
Public Sub Update(ByVal CommandText As String, ByRef MyData As DataSet)
Dim Comm As SqlCommand
If _Transaction Is Nothing Then
Comm = New SqlCommand(CommandText, Connection)
Else
Comm = New SqlCommand(CommandText, Connection, _Transaction)
End If
Dim da As New SqlDataAdapter(Comm)
da.UpdateCommand = Comm
da.Update(MyData)
End Sub
That's what I have.
It doesn't error, but it also doesn't update my DB.
I use (and I know * is bad, but it's testing) the following as the CommandText:
Code:
SELECT * FROM Customers
So I fetch a dataset using the above sql, and then I use the above update statement to save it. I know I am doing something REALLY daft.
Woka
-
Jun 16th, 2005, 05:31 PM
#2
Addicted Member
Re: DataAdapter and using .Update to save dataset
Will you attatch the file? Ill look at if u want?
-
Jun 16th, 2005, 05:34 PM
#3
Re: DataAdapter and using .Update to save dataset
Do you have 2005 Beta 2?
Woka
-
Jun 16th, 2005, 07:28 PM
#4
Re: DataAdapter and using .Update to save dataset
What is the CommandText used for the update command? Also, are you committing the transaction if and when one is used?
-
Jun 17th, 2005, 12:11 AM
#5
Re: DataAdapter and using .Update to save dataset
You're using a SELECT statement in your update command?
-
Jun 17th, 2005, 12:14 AM
#6
Re: DataAdapter and using .Update to save dataset
w00f!!! Doh!
VB/Office Guru™ (AKA: Gangsta Yoda™ ®)
I dont answer coding questions via PM. Please post a thread in the appropriate forum. 
Microsoft MVP 2006-2011
Office Development FAQ (C#, VB.NET, VB 6, VBA)
Senior Jedi Software Engineer MCP (VB 6 & .NET), BSEE, CET
If a post has helped you then Please Rate it! 
• Reps & Rating Posts • VS.NET on Vista • Multiple .NET Framework Versions • Office Primary Interop Assemblies • VB/Office Guru™ Word SpellChecker™.NET • VB/Office Guru™ Word SpellChecker™ VB6 • VB.NET Attributes Ex. • Outlook Global Address List • API Viewer utility • .NET API Viewer Utility •
System: Intel i7 6850K, Geforce GTX1060, Samsung M.2 1 TB & SATA 500 GB, 32 GBs DDR4 3300 Quad Channel RAM, 2 Viewsonic 24" LCDs, Windows 10, Office 2016, VS 2019, VB6 SP6 
-
Jun 17th, 2005, 12:15 AM
#7
Re: DataAdapter and using .Update to save dataset
-
Jun 17th, 2005, 12:23 AM
#8
Re: DataAdapter and using .Update to save dataset
 Originally Posted by mendhak
You're using a SELECT statement in your update command?
I don't think he is, although that's what I first thought from the wording. Using a SELECT statement in an UpdateCommand would raise an exception, would it not? I think it's because the transaction is not being committed. If you don't call Commit on a transaction, my guess is that it would get rolled back by default. You would receive no notification of this, as is happening. I'm pretty sure that has happened to me in the past, although it was obviously a long time ago 
Edit:
That's assuming that the route that uses a transaction is being followed. If not, forget everything I just said. In fact, I was never here!
-
Jun 17th, 2005, 02:19 AM
#9
Re: DataAdapter and using .Update to save dataset
I am using "Select * from Customers Where ID = 5", the same sql I use to get the dataset.
It's not the transaction.
I try this with or without starting a transaction, and the same thing happens.
I do no get an exception either.
I am using 2005 Beta 2, but I am assuming the ADO.NET is still the same as 2003.
Woka
-
Jun 17th, 2005, 02:28 AM
#10
Re: DataAdapter and using .Update to save dataset
Then mendhak was right. You need to use a SELECT statement to retrieve rows, a DELETE statement to delete rows, an INSERT statement to add new rows and an UPDATE statement to edit rows. You need to use something like:
Code:
UPDATE Customers SET Name = @Name WHERE ID = @ID
and then add some parameters to the SqlCommand object to substitute the actual values for the placeholders (@Name and @ID).
-
Jun 17th, 2005, 02:31 AM
#11
Re: DataAdapter and using .Update to save dataset
Hmmm...I am sure I have done this is the past where the dataset has remembered how to ties into the DB and auto updates the correct field.
Will give that a go though.
Cheers.
Woka
PS Mendhack was right coz he read my 1st post correctly hahaa
-
Jun 17th, 2005, 02:39 AM
#12
Re: DataAdapter and using .Update to save dataset
If you want to generate non-query commands automatically, you can use the "Configure Data Adapter..." function at the bottom of the properties window, assuming you have created the adapter in the designer, or you can use an SqlCommandBuilder. The command builder is frowned on in some parts and does have limitations. I never use it myself, but it is quick and easy. The Data Adapter Configuration Wizard is a liitle more involved, so gives you more control, but is still relatively easy to use.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|