Hi, i have a access database with two tables, one for customer and one for booking.

I then have a form application i made in VS 2008 which lets a user enter details such as their name phone number ect into text boxes.

All of the information the person enters thoughout the program is shown via labels at the end, all on one form.

Would it be possible to then have a button that when clicked saves all of this information into the access tables into the correct columns, im sure it must be possible i just don't really know where to start.

any help would be greatif someone knows how to do this.

Hmm ok i really dont understand what is going on at all in that link, i didnt think it would be so complicated just to save it, is there no drag and drop options?

It's not complicated at all.

Well, anything new can be daunting. Please tell me what you don't understand?

Maybe you need to read up on SQL statements as well http://www.w3schools.com/sql/sql_update.asp

The above link tells you how to update.

Here maybe this will make better sense to you: http://www.vbdotnetheaven.com/UploadFile/anair/NETDataProvidersTutorial11282005042450AM/NETDataProvidersTutorial.aspx


Here this will tell you how to make the connection:
http://www.connectionstrings.com/access-2007

You have to read to understand, and read it slowly. The first link is well commented.

Just read it again and ask me what you don't understand.

Well i just dont know what half of it is doing, take this for example:

' Create parameters for the first command.
        cmd.Parameters.Add(New  _
            OleDb.OleDbParameter("FirstName", _
            txtFirstName1.Text))
        cmd.Parameters.Add(New OleDb.OleDbParameter("LastName", _
            txtLastName1.Text))

the comment doesnt really explain much,is it taking info from those text boxes?

Also i asuume half of the other stuff like creating the datagrid is done somwhere else? I tried to download it and see what else was going on but exporting it into VS 2008 kept giving me errors and i dont have 05.

ok i think i made some progress now i put this code in:

Imports System.Data.OleDb
Public Class frmFinalInformation
    Dim inc As Integer
    Dim maxrows As Integer
    Dim con As New OleDbConnection
    Dim ds As New DataSet
    Dim da As OleDbDataAdapter
    Dim sql As String

    Private Sub frmFinalInformation_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        con.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0.;" & _
    "Data Source=F:\Database1.mdb"
        con.Open()

        sql = "SELECT * FROM tblCustomer"
        da = New OleDb.OleDbDataAdapter(sql, con)

        da.Fill(ds, "Customers")

        con.Close()

        maxrows = ds.Tables("Customers").Rows.Count
        inc = -1
End sub
        Private Sub btnSave_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnSave.Click
        Dim cb As New OleDb.OleDbCommandBuilder(da)
        Dim dsNewRow As DataRow

        dsNewRow = ds.Tables("Customers").NewRow()

        dsNewRow.Item("Customer Name") = txtFinalCustomerName.Text
        'dsNewRow.Item("Surname") = txtSurname.Text

        ds.Tables("Customers").Rows.Add(dsNewRow)

        da.Update(ds, "Customers")
        MsgBox("New Record added to the Database")
        'oledbexeption was uunhandled
        'Syntax error in INSERT INTO statement.

    End Sub

However i get an error with the da.update(ds, "Customers") line 'Syntax error in INSERT INTO statement.and i cant figure out why

ops double posted cant find the delete option

Can you tell me the table structure of Customers.

It has a Customer ID field whihch is the primary key and is auto number and a customer name field which is text, i didnt format any of them.

hmm can you comment everything and try this

new OleDbCommand("INSERT INTO Customers ([Customer Name]) VALUES (" & txtFinalCustomerName.Text & ")",con).ExecuteNonQuery()

Please bear in mind I didn't use a compiler so there maybe a syntax error.

actually try this first

dsNewRow.Item("[Customer Name]") = txtFinalCustomerName.Text

Let me know what results you achieve .

Using that method above i get the error [customer name] does not belong to tblcustomers, i removed the aquare brackets and it ran with no errors but nothing seemed to happen, i opened the database again and no record was added.

The second method i get a syntax error underlining "new"

Hmm i think i got it to work using the origional code i had before.

in my line where i specify the colum to insert to i had Customer Name and i just read somewhere that you cannot have spaces, so i changed the column name to Customer and it seems to have worked

One last thing however, the database is curentlly saved to my F drive, while the program is on my E drive, if i then took the program to my other computer withut the database where should i save it. can i use the resources folder like with pictures?

Well You can but you need [] to let it accept the name.
But yes that works too.

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.