Database Saving

N

nmrpa91290

I have a vb 2005 program that I am writing. It is just a form with a
datagridview, textbox, and import command button. The code looks like
this:

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load
'TODO: This line of code loads data into the
'TestDbDataSet.TestTable' table. You can move, or remove it, as
needed.
Me.TestTableTableAdapter.Fill(Me.TestDbDataSet.TestTable)
End Sub

Private Sub cmdImport_Click(ByVal sender As System.Object, ByVal e
As System.EventArgs) Handles cmdImport.Click
Dim col1, col2 As String
Dim NewRow As DataRow
NewRow = TestDbDataSet.Tables(0).NewRow
col1 = txtImport.Text
col2 = txtImport.Text
NewRow.Item("Data1") = col1
NewRow.Item("Data2") = col2
Try
TestDbDataSet.Tables(0).Rows.Add(NewRow)
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub

Private Sub TestTableBindingNavigatorSaveItem_Click(ByVal sender
As System.Object, ByVal e As System.EventArgs) Handles
TestTableBindingNavigatorSaveItem.Click
Me.Validate()
Me.TestTableBindingSource.EndEdit()
Me.TestTableTableAdapter.Update(Me.TestDbDataSet.TestTable)

End Sub
--------------------------------------------------------------------------------------------------------------------------------

It successfully adds rows to the datagridview control on the form.
However, it does not actually save the data into the access database
that I have created. When I open the database in Access after saving
the data in my application it is not present in the table. Nor is it
present when I close the application and then open it again. Can you
actually save the data entered in a vb 2005 independent windows
application to a previously created database? Or, does it just update
the control on the form making it look like it updated the database
table? Help would be greatly appreciated!
 
C

Cor Ligthert[MVP]

nmrpa,

The oposite from the Fill is the Update.
Beside that you needs the update commands which are standard in a Fill
command, therefore you can use the commandbuilder.

I think that this sample reach very much your question, be aware that this
is a very SQL intensive sample, only ment as sample, not to use it that way.

http://www.vb-tips.com/SQLServerUpdate.aspx

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top