Results 1 to 6 of 6

Thread: Update problem from datatable??

  1. #1

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018

    Red face Update problem from datatable??

    I have a dataset whose source is an empty access table.
    I have a datagrid "Datagrid2" whos source is a datatable "dtPick"

    I add rows to the table with the following:

    Dim rowP As DataRow
    rowP = dtPickle.NewRow()
    rowP(0) = Me.txtCode.Text
    rowP(1) = Me.txtDescription.Text
    rowP(2) = Me.txtQuantity.Text
    dtPickle.Rows.Add(rowP)

    After this code executes "Datagrid2" shows the new row but how can I see that these additions are reflected in the underlying database?

    I havent been programming .NET for long enough to figure this 1 out. Can anyone Help???

    Parksie

  2. #2
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    It's just:

    OleDbDataAdapter1.Update(DataSet11)

    ...assuming you named everything at the default.

    Is dtPickle a member of a DataSet?

  3. #3

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    Yup

    'Code from the top of my form
    Dim dtPickle As New DataTable("Pickle")
    Dim dgTSPickle As New DataGridTableStyle()
    Dim dgC1 As New DataGridTextBoxColumn()
    Dim dgC2 As New DataGridTextBoxColumn()
    Dim dgC3 As New DataGridTextBoxColumn()
    Dim dgC4 As New DataGridTextBoxColumn()

    'Onload event of form
    'Add Table to Dataset -PICKLE
    DsPICKLE1.Tables.Add(dtPickle)
    'Add columns to datatable
    dtPickle.Columns.Add(New DataColumn("Code", GetType(String)))
    dtPickle.Columns.Add(New DataColumn("Description", GetType(String)))
    dtPickle.Columns.Add(New DataColumn("Quantity", GetType(String)))
    dtPickle.Columns.Add(New DataColumn("Company", GetType(String)))
    Me.DataGrid2.DataSource = dtPickle

    'Create column styles and add to TableStyle
    Me.dgC1.MappingName = "Code"
    Me.dgC1.Width = 60
    Me.dgC1.HeaderText = "Code"
    Me.dgC2.MappingName = "Description"
    Me.dgC2.Width = 300
    Me.dgC2.HeaderText = "Item Description"
    Me.dgC3.MappingName = "Quantity"
    Me.dgC3.Width = 40
    Me.dgC3.HeaderText = "Quantity"
    Me.dgC4.MappingName = "Company"
    Me.dgC4.Width = 40
    'Add column styles to TableStyle
    Me.dgTSPickle.GridColumnStyles.Add(dgC1)
    Me.dgTSPickle.GridColumnStyles.Add(dgC2)
    Me.dgTSPickle.GridColumnStyles.Add(dgC3)
    Me.dgTSPickle.GridColumnStyles.Add(dgC4)
    Me.dgTSPickle.MappingName = "Pickle"
    'Add TableStyle to Datagrid
    Me.DataGrid2.TableStyles.Add(dgTSPickle)
    Me.DataGrid2.Refresh()

    Parksie

  4. #4
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    Hmm, if you're referring to the table as dtPickle then it's just a free DataTable as far as I can see. If it were a member of a dataset you'd have to refer to it as dsData.Tables("dtPickle"). Right?

  5. #5
    Fanatic Member
    Join Date
    Sep 2002
    Posts
    518
    This is kind of a lowbrow example but it boils down how you update a datasource from an associated dataset - all of it is bound at design time so it may not be ideal for your use, but I hope it's useful anyhow:
    Attached Files Attached Files

  6. #6

    Thread Starter
    Fanatic Member venerable bede's Avatar
    Join Date
    Sep 2002
    Location
    The mystic land of Geordies
    Posts
    1,018
    I have to put my hands up and tell you I have no idea whats happening. This .NET thing's got me going in circles.

    Using the IDE I created the connection, dataadaptor and dataset.

    I then added the datagrid and then in code created the datatable and add code.

    I'm screwed.

    I'll have a look at your example to see if I can populate my tiny mind.

    Thanks to both of you

    Parksie

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width