| | |
database not updating
Please support our VB.NET advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: May 2008
Posts: 18
Reputation:
Solved Threads: 0
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
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
its not clear..
Post the code please
Post the code please
Never tried = Never Know
So, Please do something before post your thread.
* PM Asking will be ignored *
So, Please do something before post your thread.
* PM Asking will be ignored *
•
•
Join Date: Jun 2008
Posts: 1
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: May 2008
Posts: 144
Reputation:
Solved Threads: 9
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.
•
•
Join Date: Jun 2008
Posts: 7
Reputation:
Solved Threads: 0
If you are using only commands to Insert,Update, or Delete-you should use the objCommand.ExecuteNonQuery method to update the database.
•
•
Join Date: May 2008
Posts: 18
Reputation:
Solved Threads: 0
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,
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,
•
•
Join Date: May 2008
Posts: 144
Reputation:
Solved Threads: 9
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
Then use the Adapter.Update()
to update the records
You will find all you need in this topic in MSDN - SqlDataAdapter Class
![]() |
Similar Threads
- How to Update a record in a database (PHP)
- How to insert data into database? (JSP)
- Writing to an Access Database (Visual Basic 4 / 5 / 6)
- Database is not updating but no errors :( (VB.NET)
- Updating a record in an MS Access database file using DataSets (VB.NET)
- Database not being populated.... (Java)
- updating 2 HTML tables on one PHP page (PHP)
Other Threads in the VB.NET Forum
- Previous Thread: Serial port
- Next Thread: Handle Nullable Date Field with DateTimePicker Control
| Thread Tools | Search this Thread |
.net .net2008 2005 2008 access account array basic beginner bing browser button buttons center check code crystalreport cuesent data database datagrid datagridview date datetimepicker designer dissertation dissertations dissertationtopic dropdownlist excel fade file-dialog filter forms ftp generatetags gridview hardcopy html images input insert intel internet listview mobile monitor net networking objects open output panel passingparameters pdf picturebox port position print printing problem remove save searchbox searchvb.net select serial settings shutdown soap sqlserver survey table tcp temperature text textbox timer timespan toolbox transparency trim update user vb vb.net vb.netformclosing()eventpictureboxmessagebox vb2008 vba vbnet visual visualbasic visualbasic.net visualstudio.net visualstudio2008 web winforms wpf wrapingcode year






