11 Replies - 1426 Views - Last Post: 02 February 2014 - 07:07 AM Rate Topic: -----

#1 aabonargis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-January 14

please where the error in this code

Posted 27 January 2014 - 01:45 PM

helo i need save change in data grid view to database when i press in button1 using this code
but i have some error in the code
please help me
Imports System.Data
Imports System.Data.OleDb
Public Class Form1
    Dim constr As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=|DataDirectory|\dbase.mdb"
    Dim conn As New OleDbConnection(constr)
    Dim ds As New DataSet
    Dim sql As String = "SELECT * FROM  table_parent"
    Dim bs As New BindingSource
    Dim da As New OleDbDataAdapter
    Dim da1 As New OleDbDataAdapter
    Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(da1)


    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        conn.Open()
        da = New OleDbDataAdapter(sql, conn)
        da.Fill(ds, "table_parent")
        da1 = New OleDbDataAdapter("SELECT * FROM  table_childe", conn)
        da1.Fill(ds, "table_childe")
        ds.Relations.Add("table_parent_to_table_childe", ds.Tables("table_parent").Columns("parent _id"), ds.Tables("table_childe").Columns("parent _id"), True)
        Me.TextBox1.DataBindings.Add("text", Me.ds, "table_parent.parent _id")
        Me.TextBox2.DataBindings.Add("text", Me.ds, "table_parent.Employee_name")
        Me.TextBox3.DataBindings.Add("text", Me.ds, "table_parent.Employee_bearth_date")
        Me.TextBox4.DataBindings.Add("text", Me.ds, "table_parent.Employee_address")
        Me.TextBox5.DataBindings.Add("text", Me.ds, "table_parent.Employee_fone_no")
        DataGridView1.DataSource = ds
        DataGridView1.DataMember = "table_parent.table_parent_to_table_childe"
        conn.Close()

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        Me.Validate()
        Me.da1.Update(Me.ds.Tables("table_childe"))
        Me.ds.AcceptChanges()
    End Sub
End Class




Is This A Good Question/Topic? 0
  • +

Replies To: please where the error in this code

#2 modi123_1   User is offline

  • Suitor #2
  • member icon



Reputation: 14091
  • View blog
  • Posts: 56,456
  • Joined: 12-June 08

Re: please where the error in this code

Posted 27 January 2014 - 01:47 PM

Quote

but i have some error in the code

What is the error?

What line is it happening on?
Was This Post Helpful? 0
  • +
  • -

#3 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: please where the error in this code

Posted 27 January 2014 - 02:14 PM

Do you really have a space in parent _id? That might be an issue. Not sure since it's wrapped in quotes

EDIT:
I see one thing that might be an issue, but as modi123_1 posted: Can you tell us the error you're getting?

Here's a tip that you should implement to help you.

The Form_Load event can bury a descriptive error and just notify of a exception occurring. To remedy this, wrap the code in your form load into a try catch and display the error in the catch. This will give you a more descriptive message.

But you still may have an issue with your button click event telling you there is no valid updatecommand.

This post has been edited by CharlieMay: 27 January 2014 - 02:31 PM

Was This Post Helpful? 1
  • +
  • -

#4 aabonargis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-January 14

Re: please where the error in this code

Posted 28 January 2014 - 06:46 AM

My problem is when you press the button 1 must be done to save the changes in the data network to the database

I do not owned a any problem about the "parent _id"

View Postaabonargis, on 28 January 2014 - 06:45 AM, said:

My problem is when you press the button 1 must be done to save the changes in the data grid to the database

I do not owned a any problem about the "parent _id"

Was This Post Helpful? 0
  • +
  • -

#5 DarenR   User is offline

  • D.I.C Lover

Reputation: 593
  • View blog
  • Posts: 3,823
  • Joined: 12-January 10

Re: please where the error in this code

Posted 28 January 2014 - 06:53 AM

what error message do you get?
Was This Post Helpful? 1
  • +
  • -

#6 aabonargis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-January 14

Re: please where the error in this code

Posted 28 January 2014 - 08:40 AM

i will try the code and view the error for help me
thank you for the help
Was This Post Helpful? 0
  • +
  • -

#7 aabonargis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-January 14

Re: please where the error in this code

Posted 30 January 2014 - 07:44 AM

the error message is "Update requires a valid UpdateCommand when passed DataRow collection with modified rows."

the error message is "Update requires a valid UpdateCommand when passed DataRow collection with modified rows."
Was This Post Helpful? 0
  • +
  • -

#8 DarenR   User is offline

  • D.I.C Lover

Reputation: 593
  • View blog
  • Posts: 3,823
  • Joined: 12-January 10

Re: please where the error in this code

Posted 30 January 2014 - 07:46 AM

it means you need an update command

http://www.w3schools.../sql_update.asp
Was This Post Helpful? 1
  • +
  • -

#9 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: please where the error in this code

Posted 30 January 2014 - 08:23 AM

This line
Dim builder As OleDbCommandBuilder = New OleDbCommandBuilder(da1)
has nothing to build against. At the time you do this, the commandbuilder knows nothing about the table structure.
try moving that line down into your button_click sub right after your validate line and see if that helps.
Was This Post Helpful? 1
  • +
  • -

#10 aabonargis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-January 14

Re: please where the error in this code

Posted 01 February 2014 - 09:02 AM

the both suggested solutions didn't work
please help me with another ideas

thanks
Was This Post Helpful? 0
  • +
  • -

#11 CharlieMay   User is offline

  • This space intentionally left blank
  • member icon

Reputation: 1729
  • View blog
  • Posts: 5,708
  • Joined: 25-September 09

Re: please where the error in this code

Posted 01 February 2014 - 04:55 PM

aabonargis, can you please post your code again with the changes you've made. I did a quick test and was able to set up a quick demo app using your code against my database and was able to make it work. Are you still getting the same error message?

Does your tables have primary keys in them?
Was This Post Helpful? 0
  • +
  • -

#12 aabonargis   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 16
  • Joined: 08-January 14

Re: please where the error in this code

Posted 02 February 2014 - 07:07 AM

i read your reply and checked my code Works properly after applying your remarks
thanks
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1