Cannot Make Changes To DB!

Having trouble getting changes into database

Page 1 of 1

3 Replies - 874 Views - Last Post: 25 March 2009 - 11:53 AM Rate Topic: -----

#1 AlexG788  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 28-January 09

Cannot Make Changes To DB!

Posted 25 March 2009 - 08:36 AM

Hi, I'm having trouble getting my changes to post back into the DB. I am using Access 2000 for the time being (switching over to SQL 2005 in a few 3 or 4 months). I'm having a lot of trouble converting some of the old code from VB6 to .Net 2008, mainly where database interaction is concerned.

So as a test, I have 3 columns from my database bound to datagridview on my form (DG1 in the code below), and I want to change some data in the fields and when I click "save" (button1 in the code below), I want it to save the changes in the database. I know I can do this through an SQL statement (UPDATE XXXX FROM TABLE...) but I want to just do this in the code without having to rewrite my SQL code... In VB6 we could do this under DAO by just saying rs.addnew / rs.update


 
Public Class Form1
	Dim cnString As String
	Dim strSQL As String
	Dim cn As OleDbConnection

	Dim da As OleDbDataAdapter
	Dim ds As New DataSet

	Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load


		cnString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & _ 
						"C:\Documents and settings\Desktop\Database_Portfolio_2009.mdb"
		cn = New OleDbConnection(cnString)

		strSQL = "SELECT [Txn ID], [Controller ID], [Record Date] FROM [Table Actuals] " & _
					  "WHERE [Controller ID] = 'X-1001'"

		da = New OleDbDataAdapter(strSQL, cn)
		da.Fill(ds, "Table Actuals")

		DG1.DataSource = ds.Tables("Table Actuals")

	End Sub


	Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

		Try
			ds.Tables(0).Rows(0).Item(1) = TextBox1.Text
			da.update(ds)

		Catch ex As Exception
			MessageBox.Show(ex.Message)

		End Try


	End Sub
End Class   




I've tried many different ways to do this, in this specific case I get the error ("Update unable to find Table Mapping ['Table'] or DataTable 'Table'.)

Thanks in advance for any help you can give me!

Alex

Is This A Good Question/Topic? 0
  • +

Replies To: Cannot Make Changes To DB!

#2 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: Cannot Make Changes To DB!

Posted 25 March 2009 - 09:21 AM

I do not see your data adapter's "UPDATE" or "INSERT" statements. Put that stored procedure (and column mapping in)... and you should be ready to rock and roll.
Was This Post Helpful? 0
  • +
  • -

#3 AlexG788  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 76
  • Joined: 28-January 09

Re: Cannot Make Changes To DB!

Posted 25 March 2009 - 10:45 AM

View Postmodi123_1, on 25 Mar, 2009 - 08:21 AM, said:

I do not see your data adapter's "UPDATE" or "INSERT" statements. Put that stored procedure (and column mapping in)... and you should be ready to rock and roll.


I put the da.update statement in the Try condition under the button1_click procedure. I'm kind of getting mixed up in the syntax of this though.. how would I show the table mapping in this code? Is there anything more that I have to do with the da.update(ds) statement? I saw there was options for da.updatecommand, and also there was the oledbcommandbuilder... do i need to invoke any of these?


Thanks again!
Was This Post Helpful? 0
  • +
  • -

#4 modi123_1  Icon User is offline

  • Suitor #2
  • member icon



Reputation: 13485
  • View blog
  • Posts: 53,843
  • Joined: 12-June 08

Re: Cannot Make Changes To DB!

Posted 25 March 2009 - 11:53 AM

Read this:
http://www.dreaminco...wtopic33908.htm
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1