Why isnt my data inputed going into the database table?

  • (2 Pages)
  • +
  • 1
  • 2

17 Replies - 1059 Views - Last Post: 08 June 2015 - 06:19 AM Rate Topic: -----

#1 dr4gonfire95   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-June 15

Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:10 AM

Hi guys, Im pretty new to VB and atm Im working on making a program that allows user input and with that input to fill an access database table. I type all the data and click save and nothing happens. The data does not go into the database. Sorry if the mistakes are simple but im new. Ill attach a picture of the code

http://postimg.org/image/w32jsqj7z/
Is This A Good Question/Topic? 0
  • +

Replies To: Why isnt my data inputed going into the database table?

#2 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:21 AM

Copy and paste the relevant code directly here, between code tags.
Was This Post Helpful? 0
  • +
  • -

#3 dr4gonfire95   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-June 15

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:24 AM

View Postandrewsw, on 08 June 2015 - 03:21 AM, said:

Copy and paste the relevant code directly here, between code tags.

Imports System.Data.OleDb
Public Class frmCreateOrder
    Dim strConnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=JohnsFlowers.accdb"
    Dim connection As OleDbConnection = New OleDbConnection(strConnection)
    Dim daOrders As OleDbDataAdapter
    Dim dsFlowerShop As DataSet
    Dim builder As OleDbCommandBuilder
    Private Sub grbCreateAnOrder_Enter(sender As Object, e As EventArgs) Handles grbCreateAnOrder.Enter

    End Sub

    Private Sub frmCreateOrder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim strQuery As String = "SELECT * FROM Orders ORDER BY OrderNo;"
        daOrders = New OleDbDataAdapter(strQuery, connection)
        builder = New OleDbCommandBuilder(daOrders)
        dsFlowerShop = New DataSet
        daOrders.Fill(dsFlowerShop, "Orders")

        With cbxProduct.Items
            .Add("100 Blooms of Peruvian Lilies")
            .Add("Deluxe Lavish Lavender")
            .Add("One Dozen Long Yellow Roses")
            .Add("Purple Dendrobium Orchids")
            .Add("Royal Spring Lilies")
            .Add("Two Dozen Rainbow Roses")
            .Add("Two Dozen Red Roses")
        End With
        cbxProduct.SelectedIndex = -1
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        Dim newRow As DataRow = dsFlowerShop.Tables("Orders").NewRow
        newRow.Item("OrderNo") = txtOrderNo.Text
        newRow.Item("CustomerNo") = txtCustomerNo.Text
        newRow.Item("Product") = cbxProduct.SelectedItem
        newRow.Item("Quantity") = txtQuantity.Text
        dsFlowerShop.Tables("Orders").Rows.Add(newRow)




    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#4 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:27 AM

To update the database you need to use the data-adapter's Update method:

OleDbDataAdapter.Update Method

You are adding a row to the in-memory DataTable, Update will persist it to the database.
Was This Post Helpful? 0
  • +
  • -

#5 dr4gonfire95   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-June 15

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:30 AM

Thanks for replying, so do I place it in the form or the save button?

This post has been edited by andrewsw: 08 June 2015 - 03:32 AM
Reason for edit:: Removed previous quote, just press the REPLY button

Was This Post Helpful? 0
  • +
  • -

#6 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:33 AM

It's up to you. You might have a separate button to persist all the changes back to the database when the user presses it.
Was This Post Helpful? 0
  • +
  • -

#7 dr4gonfire95   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-June 15

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:39 AM

Hmm I added the update method but its still not appearing in the database
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:50 AM

You might need to check the Copy to Output Directory property, discussed here:

How to: Manage Local Data Files in Your Project

It might be creating a new copy of the database each time.
Was This Post Helpful? 0
  • +
  • -

#9 dr4gonfire95   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-June 15

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:52 AM

No Im pretty it isnt. I have another form thats working fine and data being sent from it is going into the database and appropriate table
Was This Post Helpful? 0
  • +
  • -

#10 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 03:56 AM

One thing you should add to the top of your file is Option Strict On to help spot any type conversion errors. I am not suggesting that this will help with your current issue, but it is recommended to include it.
Was This Post Helpful? 1
  • +
  • -

#11 maceysoftware   User is offline

  • Foo
  • member icon

Reputation: 368
  • View blog
  • Posts: 1,575
  • Joined: 07-September 13

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 04:19 AM

Or you can turn option strict on project wide and see how many potential errors could happen due to incorrect conversions of types.

Right click on the Project --> Properties --> Compile

Turn OptionStrict On.

If you want option strict on for all newly created projects as default you can do this by going.

Tools --> Options --> Project and Solutions --> VB Default and turn it on there as well.
Was This Post Helpful? 0
  • +
  • -

#12 maceysoftware   User is offline

  • Foo
  • member icon

Reputation: 368
  • View blog
  • Posts: 1,575
  • Joined: 07-September 13

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 04:36 AM

also if your code is still not updating the database maybe post the code your using now? we might be able to spot something?
Was This Post Helpful? 0
  • +
  • -

#13 dr4gonfire95   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 8
  • Joined: 08-June 15

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 04:48 AM

Imports System.Data.OleDb
Public Class frmCreateOrder
    Dim strConnection As String = "Provider=Microsoft.ACE.OLEDB.12.0;Data Source=JohnsFlowers.accdb"
    Dim connection As OleDbConnection = New OleDbConnection(strConnection)
    Dim daOrders As OleDbDataAdapter
    Dim dsFlowerShop As DataSet
    Dim builder As OleDbCommandBuilder
    Private Sub grbCreateAnOrder_Enter(sender As Object, e As EventArgs) Handles grbCreateAnOrder.Enter

    End Sub

    Private Sub frmCreateOrder_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        Dim strQuery As String = "SELECT * FROM Orders ORDER BY OrderNo;"
        daOrders = New OleDbDataAdapter(strQuery, connection)
        builder = New OleDbCommandBuilder(daOrders)
        dsFlowerShop = New DataSet
        daOrders.Fill(dsFlowerShop, "Orders")
        daOrders.Update(dsFlowerShop, "Orders")
        With cbxProduct.Items
            .Add("100 Blooms of Peruvian Lilies")
            .Add("Deluxe Lavish Lavender")
            .Add("One Dozen Long Yellow Roses")
            .Add("Purple Dendrobium Orchids")
            .Add("Royal Spring Lilies")
            .Add("Two Dozen Rainbow Roses")
            .Add("Two Dozen Red Roses")
        End With
        cbxProduct.SelectedIndex = -1
    End Sub

    Private Sub btnSave_Click(sender As Object, e As EventArgs) Handles btnSave.Click

        Dim newRow As DataRow = dsFlowerShop.Tables("Orders").NewRow
        newRow.Item("OrderNo") = txtOrderNo.Text
        newRow.Item("CustomerNo") = txtCustomerNo.Text
        newRow.Item("Product") = cbxProduct.SelectedItem
        newRow.Item("Quantity") = txtQuantity.Text
        newRow.Item("Price") = txtQuantity.Text
        dsFlowerShop.Tables("Orders").Rows.Add(newRow)




    End Sub
End Class

Was This Post Helpful? 0
  • +
  • -

#14 andrewsw   User is offline

  • Stealth IT
  • member icon

Reputation: 6700
  • View blog
  • Posts: 27,542
  • Joined: 12-December 12

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 05:27 AM

You are attempting to update the data-adapter on form-load, immediately after filling the dataset. That doesn't make sense. You want to update after some changes have been made.
Was This Post Helpful? 0
  • +
  • -

#15 maceysoftware   User is offline

  • Foo
  • member icon

Reputation: 368
  • View blog
  • Posts: 1,575
  • Joined: 07-September 13

Re: Why isnt my data inputed going into the database table?

Posted 08 June 2015 - 05:29 AM

Ok, your not updating the database anywhere with that database.

Your code:

    Dim strQuery As String = "SELECT * FROM Orders ORDER BY OrderNo;"
        daOrders = New OleDbDataAdapter(strQuery, connection)
        builder = New OleDbCommandBuilder(daOrders)
        dsFlowerShop = New DataSet
        daOrders.Fill(dsFlowerShop, "Orders")
        daOrders.Update(dsFlowerShop, "Orders")



Gets the data from the database and stores the data into a object called a dataset.

The dataset holds no reference to the database its from.

When the user clicks save you will want to circle around the modified rows (however your keeping track of that, and call a update statement.

You will also need to find the newly added rows and call a insert statement for these.

and lastly you will want to find the deleted rows and call a delete statement for these.


I take back everything i just said i didn't realise there was a update method you could call on these data adapters

This post has been edited by maceysoftware: 08 June 2015 - 05:31 AM

Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2