Need help with database update-VBForums
Results 1 to 6 of 6

Thread: Need help with database update

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    169

    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

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    169

    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

  4. #4
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    Re: Need help with database update

    That is an exception and it indicates that dbOp.dtProgrmList is Nothing when that code is executed.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Oct 2013
    Posts
    169

    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")
    ...

  6. #6
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    96,602

    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.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    MSDN "How Do I?" Videos: VB | C#
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

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
  •  



Featured


Click Here to Expand Forum to Full Width

Survey posted by VBForums.