Visual Basic Development Bookmark and Share   
 Home > Visual Basic General > Add Row to Existing Table
 

Add Row to Existing Table

I am trying to add a row to an existing table within an Access database.
I have a dataset and 8 tables setup in Data Sources.

Searching on the MSDN site I found this page.
http://msdn.microsoft.com/en-us/library/bz9tthwx%28VS.80%29.aspx
but have not been able to get the updates to work. No errors come up and the data is not saved to the table
Here is the code I am using. Thank you in advance for the help.

Public Sub TestTableAddRow(ByVal sItem As String)

Dim dsQuarterMidget As New QuarterMidgetDataSet
Dim NewRowAdd As QuarterMidgetDataSet.tblDriversRow

NewRowAdd = dsQuarterMidget.tblDrivers.NewtblDriversRow

NewRowAdd.tblDriver_Name = sItem
dsQuarterMidget.tblDrivers.Rows.Add(NewRowAdd)

dsQuarterMidget.AcceptChanges()

End Sub
cpt_America  Tuesday, December 01, 2009 12:59 AM
jwavila  Tuesday, December 01, 2009 1:10 AM
Thank you for your quick response. I will check it out.
cpt_America  Tuesday, December 01, 2009 1:12 AM
Okay, I tried looking at the links and downloaded the 101 vb.net samples. Everything looks like it is dealing with SQL or datagrid. I am using an Access database connection. Looking at my code it looks like it should work. I have been looking at it all day now and my eyes are playing tricks on me. In the table I have two columns, one for a name and the other is the primary key which is automatically generated in Access. Is the AcceptChange appropriate on the dataset to write my updates or do I need to call something else?
Thank you for you time on this. I am trying to read everything that I can but am somehow have a block :(
cpt_America  Tuesday, December 01, 2009 1:57 AM
Harrie KalaChakra  Tuesday, December 01, 2009 2:22 AM
Thank you.
cpt_America  Tuesday, December 01, 2009 2:22 AM
Remove that AcceptChanges, it is a terrible knownmisleading name for a method, the same as dispose.

AcceptChanges means Accecpt the changes as updated in the databasse.

So after that you are not able to update it again and in this case never.

(If you ask yourself why it still exist, that is because persons have used it in their programs for what it does and removing it would ruin that code)


Success
Cor
Cor Ligthert  23 hours 58 minutes ago
I have read about the AcceptChanges method and understand what it really is doing. Since I have removed it from my procedure, still no luck getting the new row to save to the table. I have checked the connection state and still have connectivity to the database. This seems like a pretty straight forward thing to do just am not sure what is tripping me up or were else to look.

Thanks
cpt_America  21 hours 36 minutes ago

Use OLEDB command, it's pretty much easier ;)
Harrie KalaChakra  21 hours 26 minutes ago
Thank you, Harrie KalaChakra
the command object worked and reading about it helped me to learn it a lot more.

cpt_America  15 hours 19 minutes ago
Thank you, Harrie KalaChakra
the command object worked and reading about it helped me to learn it a lot more.


Do I miss something in this conversation?

Did you make a phone call or something, onyh Use Oledb command can in my idea not be the answer to your problem.

You never showed any command in this message thread.


Success
Cor
Cor Ligthert  13 hours 58 minutes ago

I didn't show any code here, i just posted links above.. You can check those URLs ;)

Let him learn more from those URLs, it will make him more independent and not asked more for the code
Harrie KalaChakra  5 hours 8 minutes ago
I changed the code to work with the command object. Using this I do understand it a little better. Just needed a friendly push in the right direction.

Now that I am able to add a row to my table, I ran into a little problem. Seems like when you jump a hurdle another one is on the other side. Must be what is so attractive about building your own programs.
My issue.
my data bound combobox does not show the new row. When I close the program and then reopen the row is present.
Upon researching I have tried a few things:
tried resetting the binding source of the combo box manually



Thank you again for your time.
cpt_America  4 hours 45 minutes ago

Or you can auto refresh..every time added new rows then refreshing combobox..Or maybe use timer to auto refresh every 'n' seconds
Harrie KalaChakra  3 hours 19 minutes ago

Answer then next time to the question that helped you.

This forum is used as a knowledge base.

So everybody reading this afterwardswould have the same conclusion like mine.

By the way, I assume and more can I not do, isto get the data from your dataset.

You again tell something from which we should understand how you did it, did you bind your datacombobox to a list?

But this is a complete new problem, and confirm what I wrote above, mark the messages that helped you anyhow as the answer for the future for others and start a new question.


Success
Cor
Cor Ligthert  1 hour 33 minutes ago

You can use google to search for other answers

Custom Search

More Threads

• Serial Port Communications
• Application has failed to start
• threading - moving a control
• Binding Radiobutton using vs2005
• Can you do algibra in Visual Basic?
• Register Dll file in vista..
• Use enter to activate event in textbox?
• VidControl Control steals focus
• Form Field Navigation
• Read Process Memory to get data