|
-
Feb 2nd, 2017, 03:40 AM
#1
Thread Starter
Addicted Member
Need help with database update
Hello, I have a datatable and oledbdataadapter on my class. I need to update datagridview contents when Form1 closes. I tried adding / removing dataset but got the same result.
Code:
dbOp.daProgramList.Update(dbOp.dtProgrmList)
Isn't this enough for updating a database?
The variables are declared my DatabaseOperations class like this:
Code:
Public Property dtProgramList As DataTable
Protected Friend Property Connection As New OleDbConnection
Public Property daProgramList As New OleDbDataAdapter
Public Function GetData(ByVal sqlCommand As String) As DataTable
If Not (Connection.State = ConnectionState.Open) Then
ConnectToDatabase()
End If
Dim command As New OleDbCommand(sqlCommand, Connection)
daProgramList = New OleDbDataAdapter()
daProgramList.SelectCommand = command
dtProgramList = New DataTable
dtProgramList.Locale = Globalization.CultureInfo.InvariantCulture
daProgramList.Fill(dtProgramList)
Return (dtProgramList)
End Function
-
Feb 2nd, 2017, 05:16 AM
#2
Re: Need help with database update
What actually happened when you execute that first line of code? Does it work or is an exception thrown? If the latter, what was the error message? If the former, what value did it return? If it returns a non-zero value then it is indeed saving data to your database. If that's the case but you think it's not then you're probably not looking for the data properly. In that case, follow the first link in my signature below to learn how to manage local data files.
-
Feb 2nd, 2017, 05:40 AM
#3
Thread Starter
Addicted Member
Re: Need help with database update
Thanks for the quick reply. I placed a button on form for testing. Now I'm not getting gui exception but output is like this:
Exception thrown: 'System.ArgumentNullException' in System.Data.dll
Value cannot be null.
Parameter name: dataTable
-
Feb 2nd, 2017, 07:19 AM
#4
Re: Need help with database update
That is an exception and it indicates that dbOp.dtProgrmList is Nothing when that code is executed.
-
Feb 2nd, 2017, 11:35 AM
#5
Thread Starter
Addicted Member
Re: Need help with database update
I know please help. Could this be the problem:
Code:
Public Sub InitializeDataGridView()
Dim dbOp As New DatabaseOperations()
Try
' Set up the DataGridView.
With dgv
' Set up the data source.
.DataSource = dbOp.GetData("SELECT * FROM TBL_PROGRAMS")
...
-
Feb 2nd, 2017, 06:14 PM
#6
Re: Need help with database update
I don't know how your DatabaseOperations class works. You do. You know how to create that DataTable so create it.
That said, if you're trying to save data that is already displayed in a grid then the DataTable MUST already exist, which suggests that you're actually using a different DatabaseOperations object. If you expect to save the data displayed in the grid then you have use the DataTable bound to that grid when you do the save.
Tags for this Thread
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
|