I want to save data in to my ACCESS database from textboxes. My code is here.

 Private Sub BtnSubmit_Click(sender As Object, e As EventArgs) Handles BtnSubmit.Click
 Dim cb As New OleDb.OleDbCommandBuilder(DA)
 Dim dsNewRow As DataRow
 DA = New OleDb.OleDbDataAdapter(SQL, CN)
 DA.Fill(DS, "Deposit")
 dsNewRow = DS.Tables("Deposit").NewRow()
 dsNewRow.Item("Bank") = TxtBank.Text
 dsNewRow.Item("Acno") = TxtAcno.Text
 dsNewRow.Item("Name") = TxtName.Text
 DA.Update(DS, "Deposit")
 MsgBox("New Record added to the Database")
 End Sub

On running the programme It is interrupted and getting the following message "Update requires a valid Insert Command when passed DataRow Collection with new rows". Please correct my code Or guide me how can I save the datas from my text boxes.. Thanks in advance...

Recommended Answers

All 5 Replies

        'add yourTableName
        Dim insertCommand As New OleDb.OleDbCommand("INSERT INTO yourTableName (Bank, Acno, Name) VALUES ('" & TxtBank.Text & "','" & TxtAcno.Text & "','" & TxtName.Text & "')", CN)
            MsgBox("Record Added Successfully")
        Catch ex As Exception
        End Try

Thank you...But Where should I add your code in my code,Or should I cancel all my statements and add your code in my BtnSubmit _Click Please guide me

yes replace your code with mine under btnSubmit click event

Ok thank you.. And If I want to 1.Delete a record 2.Update record after modification What changes I have to make in the above code please...

you should chnage the statment(Oledb command) like "DELETE FROM table WHERE Name =" & TxtName.Text & "" and other few modifications but this is a different question, there's a lot of free tutorials on this,try it on your own if you get any errors then post it.
if this question is solved then mark it as such
good luck.

Be a part of the DaniWeb community

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