9 Replies - 1409 Views - Last Post: 11 October 2011 - 09:03 AM Rate Topic: -----

#1 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

How to save data from datagrid

Posted 10 October 2011 - 10:23 PM

Here's my connection

Public cnn2 As New OleDb.OleDbConnection("Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\TSA-RMS\TSA-RMS\database\tsaDb.mdb")
    Public acc As String
    Public da As New OleDb.OleDbDataAdapter
    Public objcommand As New OleDb.OleDbCommand
    Public ds As New DataSet
    Public temp As String


Database : MS Access
Database Name : tsaDB.mdb
Table Name : dailyIncome
Datagrid Name : dgvDailyInc


Can you give me a sample?

By the way. How am I going to make my program locate the database even I transfer my database on other drives? I am having a hard time debugging the program after transferring my program to laptop. Database error always occur after transferring.

This post has been edited by k3nnt0ter0: 10 October 2011 - 10:27 PM


Is This A Good Question/Topic? 0
  • +

Replies To: How to save data from datagrid

#2 Elda  Icon User is offline

  • D.I.C Regular

Reputation: 31
  • View blog
  • Posts: 314
  • Joined: 30-December 10

Re: How to save data from datagrid

Posted 10 October 2011 - 10:29 PM

See it here
Was This Post Helpful? 0
  • +
  • -

#3 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: How to save data from datagrid

Posted 10 October 2011 - 10:58 PM

View PostElda, on 10 October 2011 - 11:29 PM, said:

See it here


Uhmm. . It seems like the problem in that link was saving data from textbox.
I know how to save from textbox but I don't know in datagrid. It's complicated for me :)
Was This Post Helpful? 0
  • +
  • -

#4 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: How to save data from datagrid

Posted 11 October 2011 - 12:10 AM

Or may be this
Was This Post Helpful? 0
  • +
  • -

#5 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: How to save data from datagrid

Posted 11 October 2011 - 02:59 AM

View Postsmohd, on 11 October 2011 - 01:10 AM, said:

Or may be this

I still don't get it :no:
Was This Post Helpful? 0
  • +
  • -

#6 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: How to save data from datagrid

Posted 11 October 2011 - 04:40 AM

I sorry for wrong link first, I miss read your question, that link shows how to retrieve data from database to grid.
But how did you retrieve data from the table to grid which you want to change update now? Because if your data adapter has a connection to a source, then we can feed data and ask it to update..
Was This Post Helpful? 0
  • +
  • -

#7 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: How to save data from datagrid

Posted 11 October 2011 - 04:56 AM

View Postsmohd, on 11 October 2011 - 05:40 AM, said:

I sorry for wrong link first, I miss read your question, that link shows how to retrieve data from database to grid.
But how did you retrieve data from the table to grid which you want to change update now? Because if your data adapter has a connection to a source, then we can feed data and ask it to update..


Don't mind it :bigsmile:

I haven't done yet the data retrieval. Should I do that first?
Was This Post Helpful? 0
  • +
  • -

#8 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: How to save data from datagrid

Posted 11 October 2011 - 05:06 AM

It depends on what you need to do, but we must use have a data set with table and an adapter to update the data source.
If you want to call the table, preview it in data grid, do changes and then update, yes then you need to call data first to the grid so the data set associated to it will know changes that has been done(either adding new rows or make changes to the existing rows)
Was This Post Helpful? 0
  • +
  • -

#9 k3nnt0ter0  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 181
  • Joined: 16-January 10

Re: How to save data from datagrid

Posted 11 October 2011 - 05:26 AM

View Postsmohd, on 11 October 2011 - 06:06 AM, said:

It depends on what you need to do, but we must use have a data set with table and an adapter to update the data source.
If you want to call the table, preview it in data grid, do changes and then update, yes then you need to call data first to the grid so the data set associated to it will know changes that has been done(either adding new rows or make changes to the existing rows)


Correct me if I'm wrong. Is the adapter you are talking about the one stated at post #1?
I'll place some data on my database. Help me call it.
Was This Post Helpful? 0
  • +
  • -

#10 smohd  Icon User is offline

  • Critical Section
  • member icon



Reputation: 1746
  • View blog
  • Posts: 4,409
  • Joined: 14-March 10

Re: How to save data from datagrid

Posted 11 October 2011 - 09:03 AM

Yes indeed, you will need to initialize it and pass to it the connection and the query to be executed. After that you will use its Fill() method to fill the data set. Then get the table from data set and add it to the grid view.
Simple enough like this pseudo:
objcommand.CommanText = "query"
objcommand.COnnection = yourConnection
da = New OleDbDataAdapter(objcommand)
da.Fill(ds, "TableName")
datagrid.DataSource = ds.Table(0)
Implement it and ou will be happy.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1