dataset problems - cant update sql after editing dataset 
Author Message
 dataset problems - cant update sql after editing dataset

Heres the problem 3 buttons on the form do simple steps.  b1 loads a
dataset called dataset21.
B2. processes field that currently has first and last name with comman
seperator. and puts first
and last name in its own field.
B3. updates the sql database.

If i use B1 to fill a datagrid on the form. Then change any field then
use the update button. (Button3) IT works as it should and the sql
database is updated.

If i use B1 to fill and then B2 to run the process and then B3 to
update. The datagrid shows that the process changed the dataset
correctly, but when the update is performed, nothing happens to the
sql database.
Before the line was put in to refresh the datagrid before updating,
an error would appear regarding. concurrency violations, which i took
to mean that i was trying to update something that the adapter was
trying to update. But im not sure about that. Adding the refresh cured
that, but the sql database is not ever updated when the process runs.

Private Sub Button1_Click(ByVal...
        DataSet21.Clear()
        OleDbDataAdapter1.Fill(DataSet21)
End Sub

Private Sub Button2_Click(ByVal...
     Dim x, y, hold1 As Integer
     Dim mydatarow As DataRow
     Dim check1, fname, lname, name1 As String
     Cursor.Current = Cursors.WaitCursor
     For Each mydatarow In Me.DataSet21.Tables("Data_Employees").Rows
        name1 = (mydatarow("holdname").ToString())
        hold1 = Len(name1)
        For x = 1 To hold1
             check1 = name1.Substring(x - 1, 1)
             If check1 = "," Then
                  lname = name1.Substring(0, x - 1)
                  fname = name1.Substring(x + 1, (hold1 - x) - 1)
                  mydatarow.BeginEdit()
                  mydatarow.Item("Firstname") = fname
                  mydatarow.Item("Lastname") = lname
                  mydatarow.AcceptChanges()
                  Exit For
             End If
        Next
     Next
     DataSet21.AcceptChanges()
     DataGrid1.Refresh()
End Sub

Private Sub Button3_Click(ByVal....
     OleDbDataAdapter1.Update(DataSet21)
     MessageBox.Show("Database updated!")
End Sub

What am i doing wrong.  How do i get the database to update after
running a process on the dataset and changed datarows.
Thanks in advance.



Tue, 26 Jul 2005 06:57:38 GMT  
 dataset problems - cant update sql after editing dataset
Donald,
I don't know if this will help, but I ran into a
concurrency message updating an Access database.

What I discovered, is that whe I looked at the
oledbadapter (you would use the sql adapter) properties.
I went to the update command and expanded it.  Clicked on
command text and clicked the "..." button.  This displays
the update command in the querry builder.  I discovered in
the Where part of the sql statement was a number of
conditions that were NOT the unique data key.  I removed
all of these EXCEPt thew key (you can edit the select
statement or click off the icons that look like wine
glasses at the top window that list the fields).

Concuurency problem went away.  I suggest you comment off
the refresh (I believe this is removing your changes which
is why you don't see anything updating) and try "fixing"
the update statement as described above.  I would note
iwhat it was 1st so you can put it back if this makes it
worse.  ;)

Good luck,
Peter

Quote:
>-----Original Message-----
>Heres the problem 3 buttons on the form do simple steps.  
b1 loads a
>dataset called dataset21.
>B2. processes field that currently has first and last
name with comman
>seperator. and puts first
>and last name in its own field.
>B3. updates the sql database.

>If i use B1 to fill a datagrid on the form. Then change
any field then
>use the update button. (Button3) IT works as it should
and the sql
>database is updated.

>If i use B1 to fill and then B2 to run the process and
then B3 to
>update. The datagrid shows that the process changed the
dataset
>correctly, but when the update is performed, nothing
happens to the
>sql database.
>Before the line was put in to refresh the datagrid before
updating,
>an error would appear regarding. concurrency violations,
which i took
>to mean that i was trying to update something that the
adapter was
>trying to update. But im not sure about that. Adding the
refresh cured
>that, but the sql database is not ever updated when the
process runs.

>Private Sub Button1_Click(ByVal...
>    DataSet21.Clear()
>    OleDbDataAdapter1.Fill(DataSet21)
>End Sub

>Private Sub Button2_Click(ByVal...
>     Dim x, y, hold1 As Integer
>     Dim mydatarow As DataRow
>     Dim check1, fname, lname, name1 As String
>     Cursor.Current = Cursors.WaitCursor
>     For Each mydatarow In Me.DataSet21.Tables

("Data_Employees").Rows

- Show quoted text -

Quote:
>    name1 = (mydatarow("holdname").ToString())
>    hold1 = Len(name1)
>    For x = 1 To hold1
>         check1 = name1.Substring(x - 1, 1)
>         If check1 = "," Then
>              lname = name1.Substring(0, x - 1)
>              fname = name1.Substring(x + 1, (hold1 -
x) - 1)
>              mydatarow.BeginEdit()
>              mydatarow.Item("Firstname") = fname
>              mydatarow.Item("Lastname") = lname
>              mydatarow.AcceptChanges()
>              Exit For
>         End If
>    Next
>     Next
>     DataSet21.AcceptChanges()
>     DataGrid1.Refresh()
>End Sub

>Private Sub Button3_Click(ByVal....
>     OleDbDataAdapter1.Update(DataSet21)
>     MessageBox.Show("Database updated!")
>End Sub

>What am i doing wrong.  How do i get the database to
update after
>running a process on the dataset and changed datarows.
>Thanks in advance.
>.



Wed, 27 Jul 2005 04:39:39 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. cant update dataset - form closing

2. Dataset changes updates grid , How to update SQL table

3. updating a dataset to the SQL Database

4. Updating a SQL-Table form modified Dataset.

5. Cannot DataSet.ReadXml a file written with DataSet.WriteXml

6. How to generate dataset class from dataset xsd file

7. Problem with Updating Dataset contents back to db when using data binding

8. To DataSet or Not to DataSet

9. dataset : cannot fil the dataset because the field is empty

10. dataset update problem solved

11. Dataset update problem

12. DataSet Update Problem.

 

 
Powered by phpBB® Forum Software