database not updating

Please support our VB.NET advertiser: Intel Parallel Studio Home
Reply

Join Date: May 2008
Posts: 18
Reputation: deepukng is an unknown quantity at this point 
Solved Threads: 0
deepukng deepukng is offline Offline
Newbie Poster

database not updating

 
0
  #1
Jul 4th, 2008
Dear friends,

I am using Vb.net as front end and Sqldatabase as my database file. In my application actual data is not updaing in to the database. But it shows the data while running. Once if clsoe the eecution and if i check the table the data is not saved in the table. i am not able to find the error. Please help me ...


Thanking you,
Deepak
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2,641
Reputation: Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light Jx_Man is a glorious beacon of light 
Solved Threads: 245
Jx_Man's Avatar
Jx_Man Jx_Man is offline Offline
Posting Maven

Re: database not updating

 
0
  #2
Jul 4th, 2008
its not clear..
Post the code please
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 1
Reputation: ITSoon is an unknown quantity at this point 
Solved Threads: 0
ITSoon ITSoon is offline Offline
Newbie Poster

Re: database not updating

 
0
  #3
Jul 4th, 2008
I am having the same problem with an Access database. I have attached my code of the button event if anyone could help I would appreciate it.

Private Sub btnSaveData_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSaveData.Click


Dim ds As New DataSet
Dim strConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0;" & "Data Source= C:\Documents and Settings\Robert\My Documents\Chapter 10\flower.mdb"
Dim objConnection = New OleDbConnection(strConnectionString)
Dim strSQL As String = "SELECT * FROM flower"
Dim Connection As New SqlConnection
Dim objCommand As New OleDb.OleDbCommand(strSQL, objConnection)
Dim Command As New SqlCommand("INSERT INTO flower(Number, Name, Meaning) VALUES (FlowerNumber, FlowerName, FlowerMeaning)", Connection)
Dim objDataAdapter As New OleDb.OleDbDataAdapter(objCommand)
Dim objDataTable As New Data.DataTable("flower")
Dim objDataRow As DataRow

Try
'Open the database connection
objConnection.Open()

'Fill the DataTable object
objDataAdapter.Fill(objDataTable)

'Load the list box on the form

Dim dsNewRow As DataRow
For Each dsNewRow In objDataTable.Rows
Console.WriteLine(dsNewRow.Item("FlowerNumber") & " " & _
dsNewRow.Item("FlowerName") & " " & dsNewRow.Item("FlowerMeaning") & " ")
Next
Catch OleDbExceptionErr As OleDb.OleDbException
'Write the exception
Console.WriteLine(OleDbExceptionErr.Message)
Catch InvalidOperationExceptionErr As InvalidOperationException
'Write the exception
Console.WriteLine(InvalidOperationExceptionErr.Message)
End Try

'Close the database connection
objConnection.Close()


'Clean up
objDataRow = Nothing
objDataTable.Dispose()
objDataTable = Nothing
objDataAdapter.Dispose()
objDataAdapter = Nothing
objCommand.Dispose()
objCommand = Nothing
objConnection.Dispose()
objConnection = Nothing




btnNewFlower.Enabled = True
btnSaveData.Enabled = False
btnDelete.Enabled = True
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: database not updating

 
0
  #4
Jul 4th, 2008
You must either add an Update Command to the Adapter-just as you have done for the SELECT and INSERT Command or use the Commandbuilder to do it. Then use the Adapters Update method (just like Fill) to update the dataset to the database. Besides this, you dont need to open and close the Connection when using an Adapter. The Adapter does that automatically when you call the Fill method and closes the Connection Automatically after the Update.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 18
Reputation: deepukng is an unknown quantity at this point 
Solved Threads: 0
deepukng deepukng is offline Offline
Newbie Poster

Re: database not updating

 
0
  #5
Jul 5th, 2008
Thank you very much for the reply. But my problem is something different. in my code snippet sometimes i use only sql commands to insert, update and delete command. that time data is is not updating in my database. pls heil me....


thanking you ,
Deepak
Reply With Quote Quick reply to this message  
Join Date: Jun 2008
Posts: 7
Reputation: regcure is an unknown quantity at this point 
Solved Threads: 0
regcure regcure is offline Offline
Newbie Poster

Re: database not updating

 
0
  #6
Jul 5th, 2008
If you are using only commands to Insert,Update, or Delete-you should use the objCommand.ExecuteNonQuery method to update the database.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: database not updating

 
0
  #7
Jul 5th, 2008
You will also have to use Parameters to pass data to the Insert,update, delete commands.
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 18
Reputation: deepukng is an unknown quantity at this point 
Solved Threads: 0
deepukng deepukng is offline Offline
Newbie Poster

Re: database not updating

 
0
  #8
Jul 5th, 2008
Thank you for the useful information..
Here is one more problem when i am using update command with data adapter, i getting error msg:"Update requires a valid UpdateCommand when passed DataRow collection with modified Rows ". I have checked the code and database. i am not able to find the error. please help me out to find the error,

Thanking you,
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 144
Reputation: sierrainfo is an unknown quantity at this point 
Solved Threads: 9
sierrainfo sierrainfo is offline Offline
Junior Poster

Re: database not updating

 
0
  #9
Jul 5th, 2008
I posted the solution a few hrs ago. You have to create a Command Object for Update-just like you have done for Select and Insert. Add the Update code (Update table -- set--where==etc) and Add Parameters for the Update. Specify values for the Parameters.

Then use the Adapter.Update()
to update the records
You will find all you need in this topic in MSDN - SqlDataAdapter Class
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 18
Reputation: deepukng is an unknown quantity at this point 
Solved Threads: 0
deepukng deepukng is offline Offline
Newbie Poster

Re: database not updating

 
0
  #10
Jul 5th, 2008
tahnk you very much...
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC