What do I need to do to get this to work Add Record

  • Thread starter Thread starter Charles May
  • Start date Start date
C

Charles May

OK,
First off, I am using the Server Explorer to create the database objects in
case that matters.

I have created a connection to an access database along with 2 adapters
daClient (Client table) & daLog (Log table)
both use dsServiceLog as the datasource

My form has a combobox which is set to DataSource = dsServiceLog,
DataMember= client.client and ValueMember = client.clientID

I have created a one to many relationship in the datasource
Client.ClientID -< Log.ClientID

There is also dtpDate (datetimepicker) bound to dsServiceLog and DataField =
Log.Date

I also have 3 textboxes bound to 3 other columns in the Log Table

Here is my problem

When the form loads I daClient.Fill(dsServiceLog)

This fills the combobox with all clients
I set the date, and add the text to the other 3 boxes and click ok to save
the data to the Log table in the database

When I go in to look at the table, a record is added but the ClientID is
blank all other data is there



so, I created this line

daLog.InsertCommand.Parameters(1).Value = Me.cboClient.SelectedValue

still the same result though. How can I set parameter 1 for an insert
statement, this is the method I used for a InsertSelect so I am assuming I
do the same for InsertSelect.

Here is the code I am using

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

daClient.Fill(DsServiceLog)

BindingContext(DsServiceLog, "Log").EndCurrentEdit()

BindingContext(DsServiceLog, "Log").AddNew()

End Sub



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

daLog.InsertCommand.Parameters(1).Value = Me.cboClient.SelectedValue

BindingContext(DsServiceLog, "Log").EndCurrentEdit()

'TextBox1.Text = cboClient.SelectedValue

daLog.Update(DsServiceLog)

DsServiceLog.AcceptChanges()

End Sub

I had the textbox.text on to display the value and it is indeed the ClientID
of the selected combobox item

Anyone see what the problem could be or is there a better way of doing this?
I'm new to using databound controls so I'm not even sure if I'm on the right
track.

Thanks

Charlie
 
Hi Charles,

I don't think that is wise setting parameters of commands used for update.
In fact, you shouldn't.
Update method takes care of setting parameters (the values are retrieved
from given table).
So, if you have properly mapped parameters, Update method alone is enough
(no need to set parameters value manually).
 
Miha,
Thanks, I discoverd that when somone in the databinding newgroup told me to
add the Log.ClientID to the valuemember of the combobox.

Thanks for the reply

Charlie
 
Back
Top