Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
How to Update Not Bounded Fields
Message
From
12/01/2003 12:16:31
 
General information
Forum:
ASP.NET
Category:
ADO.NET
Miscellaneous
Thread ID:
00739818
Message ID:
00740797
Views:
40
No, myDR will always be Rows[0]. What you need to do is change the statement to something like this:
int i = BindingContext(myDS, "Company").Position
myDS.Tables("Company").Rows(i)("CompanyID") = 10
~~Bonnie


>Although this statment in the bigining of the LoadForm, and also in the Add procedure I am changing the .position and the .SelectedIndex, this would not effect?
>
>
>>You're setting myDR to Rows[0] in your DataSet and then you wonder why it updates Rows[0] instead of a new row that you just added??? That's what you're telling it to do ... it does what you say, not what you mean. <g>
>>
>>
>>
>>>myDR (DataRow), came from the following code & yes I am using the ComboBox datasource the same as my main DataSet, is this a wrong way?
>>>
>>>Code :
>>>
>>>Dim myDR As DataRow
>>>Private Sub frm_Company_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
>>> Try
>>> myDA.Fill(myDS, "Company")
>>> Catch
>>> MsgBox(Err.Description, Err.Number)
>>> End Try
>>>
>>> ' Will fill the myDR only if there are Rows in the Table
>>> If myDS.Tables("Company").Rows.Count <> 0 Then
>>> myDR = myDS.Tables("Company").Rows(0)
>>> Else
>>> MsgBox("Table Empty, No Data Available.")
>>> End If
>>> Call DataBinding()
>>>End Sub
>>>
>>>Then I call the databinding sub
>>>
>>>Private Sub DataBinding()
>>> Me.cbSelect.DataSource = myDS.Tables("Company").DefaultView
>>> Me.cbSelect.DisplayMember = "CompanyID"
>>>
>>> Me.txtEnter.DataBindings.Add("Text", myDS.Tables("Company").DefaultView, "Entered")
>>> Me.txtCompanyName_e.DataBindings.Add("Text", myDS.Tables("Company").DefaultView, "CompanyName_e")
>>> Me.txtCompanyName_a.DataBindings.Add("Text", myDS.Tables("Company").DefaultView, "CompanyName_a")
>>>End Sub
>>>
>>>
>>>
>>>>Ahmad,
>>>>
>>>>A few questions:
>>>>
>>>>You have the following statement in the btnSave_Click() method:
>>>>
>>>>    myDR("CompanyID") = 10
>>>>
>>>>Where does myDR come from? I don't see the code for that. Perhaps you're doing that part wrong.
>>>>
>>>>Also, another possibility might be something wrong with how you're doing the combobox. What is the DataSource for your combo? It should *not* be the same DataSet that you are binding too ... if you *are* doing that, then that might explain your problems.
>>>>
>>>>~~Bonnie
>>>>
>>>>
>>>>You have
>>>>>I did all this trace in the last 2 days, I found somthing strange, see what it's happening:
>>>>>
>>>>>Remember the code I sent you before about adding a new Row to the DS, starts from there :
>>>>>**1 ))
>>>>
>>>>>Private Sub btnAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnAdd.Click
>>>>>        pbbolAddNew = True
>>>>>
>>>>>        myDA.InsertCommand = myCB.GetInsertCommand
>>>>>
>>>>>        With BindingContext(myDS, "Company")
>>>>>            .AddNew()
>>>>>            .Position = .Count - 1
>>>>>            cbSelect.SelectedIndex = .Count - 1
>>>>>        End With
>>>>>End Sub
>>>>
>>>>>
>>>>>**2 ))
>>>>>The form will be active for user entry, then user should click the Save button here.... up to here all trace and operations are fine, Save Code:
>>>>>
>>>>
>>>>>Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
>>>>>' ** this is the manual update for the ID field
>>>>>     myDR("CompanyID") = 10
>>>>>
>>>>>     ' Call update data procedure
>>>>>       Call UpdateDS()
>>>>>
>>>>>' ** 3 pls the notes down **
>>>>>
>>>>>       Call MyFormStandard()
>>>>>       Call MyDisableEnable()
>>>>>End Sub
>>>>>
>>>>>Private Sub UpdateDS()
>>>>>        Try
>>>>>            Me.BindingContext(myDS, "Company").EndCurrentEdit()
>>>>>            myDA.Update(myDS, "Company")
>>>>>        Catch
>>>>>            ' Error will be displayed if another user edited the data same time
>>>>>            funMsgCenter(Err.Description, Err.Number)
>>>>>            funMsgCenter("Data Not Saved/Deleted, Reload Your Data.", "")
>>>>>            myDS.RejectChanges()
>>>>>        End Try
>>>>>
>>>>>        myDS.AcceptChanges()
>>>>>End Sub
>>>>
>>>>>
>>>>>Notes for #3:
>>>>>the problem starts here the typed data in the form is stored to the new row correctly, but the new ID value saved in the first Row in the ComboBox
>>>>>and the new saved row remain with a blank manual ID !!
>>>>>How the row position jumbed from the new row (.position = last row) to the first row!!
>>>>>This I don't understand it?
>>>>>
>>>>>
>>>>>
>>>>>>Ahmad,
>>>>>>
>>>>>>No, the DataBinding is NOT your problem. Updating the backend database from a DataSet that has been modified both manually and through data-bound controls works just fine. I've done it many times ... something else is wrong, but at this point I don't know what to suggest any more. If none of the things that I've suggested have worked, then I guess you need to try and focus more on *where* the problem is happening. Trace and step through your code and check your data both before and after you have made changes. Check and see what the RowState is before and after. Things like that ... I don't think I can offer any more suggestions unless I have more information.
>>>>>>
>>>>>>~~Bonnie
>>>>>>
>>>>>>
>>>>>>>Hi Bonnie
>>>>>>>
>>>>>>>It's still the same problem, and all that because of the DataBinding.
>>>>>>>Do you advice to leave the DataBinding and do all the thing by codding, as I used to do in the ole days VB6 ?
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Reply
Map
View

Click here to load this message in the networking platform