Results 1 to 3 of 3

Thread: Save data to DB via OleDbDataAdapter and binding source, change value of one column

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Save data to DB via OleDbDataAdapter and binding source, change value of one column

    Hi!
    I'm updateing my DB via an OleDbDataAdapter:
    Code:
    insertCommand = New OleDbCommand("INSERT INTO bundle (num,  document_id, .....) " & _
                                                         "VALUES (@num, @document_id, .... )", conn)
    insertCommand.Parameters.Add("@num", OleDbType.Integer, 4, "num")
    insertCommand.Parameters.Add( "@document_id", OleDbType.Integer, 4, "document_id")
    Currently I have some DataGridViewComboBoxColumns with DataSource set to a DataTable read from database, with
    Code:
    myBindingSource.DataSource = "store_id"
    With myComboBoxColumn
                .DataSource = alternativesDataTable 'filled from a separate table in the database
                .DataPropertyName = myBindingSource.DataSource()
                .DisplayMember = "title"
                .ValueMember = "id"
                .HeaderText = "MyColumn"
    End With
    How can I achieve something like this in pseudo code:
    Code:
    insertCommand.Parameters.Add("@sortiment", OleDbType.VarChar, 20, "store_id"->DisplayMember )
    I cannot change the valueMember to be "title", as some titles contain percentage sign(%), which causes an error.

  2. #2
    PowerPoster dunfiddlin's Avatar
    Join Date
    Jun 2012
    Posts
    8,245

    Re: Save data to DB via OleDbDataAdapter and binding source, change value of one colu

    as some titles contain percentage sign(%), which causes an error
    Then it will cause an error no matter by whatever method you derive it, will it not?
    As the 6-dimensional mathematics professor said to the brain surgeon, "It ain't Rocket Science!"

    Reviews: "dunfiddlin likes his DataTables" - jmcilhinney

    Please be aware that whilst I will read private messages (one day!) I am unlikely to reply to anything that does not contain offers of cash, fame or marriage!

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Apr 2013
    Posts
    134

    Re: Save data to DB via OleDbDataAdapter and binding source, change value of one colu

    The %-sign problem occurs only when I use the value as ValueMember to bind it to the bindingsource with the same string value with percent sign.
    Now I want to use the OleDbDataAdapter functionality, but for this one value I need to insert back the sertificate name to the database row. The reason is, that I have solved the binding problem by creating and using an id, but the database gets synchronised to the main database with this silly whole-name-column. It is then used in many different reports, so I cannot update the main database right now, as this will include a lot of changes in other code.
    But I just understood, that I can solve this with a simple additional SQL statement. After I will call the DataGridView.Update method, I will call an sql statement to set this column based on the newly assigned id.

    Maybe I can add an additional column to the DGV and set it's value to the displayMember of another column and use this column as the source for the parameter. This should be possible.

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