Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hello everybody,

I'm killing myself with the following problem.

I have a DataGrid and two buttons below. The first button1 executes the following code:

       Dim Counter As Integer

       Dim MyTable As DataTable = Me.Sim_DataSet.Tables("SimVariablesValues")

       For Counter = Convert.ToInt32(VVfrom_txtbox.Text) To Convert.ToInt32(VVto_txtbox.Text) Step Convert.ToInt32(VVStep_txtbox.Text)
           Dim NewEntry As DataRow = MyTable.NewRow
           NewEntry(0) = Me.FormID
           NewEntry(1) = Counter
           NewEntry(2) = Counter
           MyTable.Rows.Add(NewEntry)
           Console.WriteLine("Counter:" & Counter)
       Next

       Me.Sim_DataSet.AcceptChanges()
       Sim_SqlDataAdapter.Update(Sim_DataSet.SimVariablesValues)

 

 

the second button2 executes this one:

Sim_SqlDataAdapter.Update(Sim_DataSet.SimVariablesValues)

 

 

If I add values in the DataSheet per hand and press the button2 all values from DataGrid is transferred to Ms SQL Server.

 

If I press the button1, DataGrid shows the new values, but the data is not transferred to Ms SQL Server.

 

Do I do anything wrong with Sim_SqlDataAdapter.Update(Sim_DataSet.SimVariablesValues) ?!?!??!?!

 

I would appreciate any help!

Greetings, cygent

Posted

I found my error. I had to put AccepedChanges at the end :-) like that:

 

       Dim Counter As Integer

       Dim MyTable As DataTable = Me.Sim_DataSet.Tables("SimVariablesValues")

       For Counter = Convert.ToInt32(VVfrom_txtbox.Text) To Convert.ToInt32(VVto_txtbox.Text) Step Convert.ToInt32(VVStep_txtbox.Text)
           Dim NewEntry As DataRow = MyTable.NewRow
           NewEntry(0) = Me.FormID
           NewEntry(1) = Counter
           NewEntry(2) = Counter
           MyTable.Rows.Add(NewEntry)
           Console.WriteLine("Counter:" & Counter)
       Next

       Sim_SqlDataAdapter.Update(Sim_DataSet.SimVariablesValues)
Me.Sim_DataSet.AcceptChanges()

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...