Hi.
Im doing a program that connects a form to access database.
Problem: I have a button that saves all the new information entered in the text boxes I have. When I click SAVE it shows a message that "A new record has been added to the database" but when I look in the database..its not there..

PLS. HELP!


thanks in advance

Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
con = New OleDb.OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0;Data Source = C:\Documents and Settings\God\My Documents\Visual Studio Projects\test\HostingDB.mdb")
da = New OleDb.OleDbDataAdapter("SELECT * FROM tblContact1", con)
If inc <> -1 Then
NavigateRecords()
Dim drow As DataRow
Dim dcmdbuilder As New OleDb.OleDbCommandBuilder(da)
da.MissingSchemaAction = MissingSchemaAction.AddWithKey
da.Fill(ds, "HostingDB")
drow = ds.Tables("HostingDB").NewRow()
drow("ID") = txtCiD.Text + 1
drow("CName") = txtCName.Text
drow("PCont") = txtPCont.Text
ds.Tables("HostingDB").Rows.Add(drow)
ds.AcceptChanges()
da.Update(ds, "HostingDB")
MsgBox("New record added to the database")
End If
 
btnSave.DialogResult = DialogResult.OK
btnUpdate.Visible = True
btnUpdate.Enabled = True
btnNew.Visible = True
btnNew.Enabled = True
btnDel.Visible = True
btnDel.Enabled = True
btnSave.Visible = False
btnCancel.Visible = False
 
End Sub

Recommended Answers

All 6 Replies

Have you doulbe checked your "alias" names for the columns you are populating. One thing to also do is the use the GetChanges() method of the dataadpter to see if you are getting the row(s) you added returned.

I checkd everything...

I tried creating another version of this as a "TEST" (less columns) it worked on it...SAME CODING and stuff..
but this one seems to be not working.

-maybe its the database fault??

is ther like a LIMIT for columns in a connection or something???

Thanks

-someone help???

Member Avatar for user23490234

You have to get rid of your line ds.AcceptChanges.

You need to do this because ds.AcceptChanges will turn all of your rows in the dataset to datarowstate.Unchanged. Which means that when you do the da.Update there are no records to update.

If you need more information on this let me know.

Thank you,
JJD

Hi,

Thanks vbismee....but when I take out ds.Acceptchanges .......an error shows up........to the da.Update(ds, "HostingDB")....

Error: Syntax ERROR in INSERT INTO Statement....

Member Avatar for user23490234

Is the ID column an AutoNumber?
If it is you should not set the ID column when you add the row.
If not then what is the rest of the error code?

If you want to talk to quicker, send me a private message and I will send you my email address.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.