Problems with Access database and DataAdapter

If you need help with a project or need to know how to do something specific in VB.NET then please ask your questions in here.
Forum rules
Please LOCK your topics once you have found the solution to your question so we know you no longer require help with your query.
9 posts Page 1 of 1
Contributors
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Hello,

I am having horrible trouble with the DataAdapter, which I just learned to use yesterday. I am learning database working in VB.NET, and this is my problem.

I get a line highlighted:
Code: Select all
DataAdapter.Update(DataSet, "Invoices")
and the error says "Syntax error in INSERT INTO statement."

Download the source files for this project (and Access database too) here:
Invoice Manager.zip
Please look around in the source code and tell me what is wrong. I don't see anything wrong! Please help! +rep to first correct answerer!

~GoodGuy17 :D
You do not have the required permissions to view the files attached to this post.
User avatar
Dummy1912
VIP - Donator
VIP - Donator
Posts: 1969
Joined: Sat Aug 21, 2010 2:17 pm

hello,

well I'm not sure but you use UPDATE
i have seen the database file
and i don't see any autonumber (this create a recordno by its self like 1 2 3 4 5 ect...)
because you will need this to update the current record.
so the update will not work. i guess

so if you load a data it will read the autonumber and load the record when you press update this will overwrite the current info from that autonumber.
visit us on:


http://www.softpedia.com/get/System/Lau ... -Run.shtml
Check it out ! http://www.softpedia.com/publisher/I-A- ... 90017.html
Check it out ! http://www.softpedia.com/get/Desktop-En ... lock.shtml
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Can you show me how to add autonumbers? I don't know anything with Access, but I am trying to learn using databases from them with VB :P
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

I couldn't make much sense out of using DataAdapter in that way. You can list, add, and remove database records with this:
Code: Select all
        'table name is Invoices

        Dim odc As OleDbConnection = New OleDbConnection("PROVIDER=Microsoft.Jet.OLEDB.4.0; Data Source=Invoices.mdb")

        odc.Open()

        'read the records + some attributes
        Dim cmd As OleDbCommand = odc.CreateCommand()
        cmd.CommandText = "SELECT * FROM Invoices"
        Dim res As OleDbDataReader = cmd.ExecuteReader()
        Dim current As Integer = 0
        While res.Read()
            For i As Integer = 0 To res.FieldCount - 1
                MsgBox(current & ": " & res.GetName(i) & ": " & res.Item(i) & " [" & res.GetDataTypeName(i) & "]")
            Next
            current += 1
        End While
        res.Close()

        'add a record
        cmd.CommandText = "INSERT INTO Invoices VALUES ('user', 5, 15/03/2011, 'address', 'service')"
        cmd.ExecuteNonQuery()

        'remove user's record
        cmd.CommandText = "DELETE * FROM Invoices WHERE name='user'"
        Dim affected As Integer = cmd.ExecuteNonQuery()
        MsgBox(affected & " rows deleted")

        odc.Close()
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Mandai, the way I am learning it is from here:
http://homeandlearn.co.uk/NET/nets12p1.html

Note that if you just view that, you will get misinformed; I am learning NON Data Source, I am trying to make it from scratch myself. Just scan through the parts in the database teacher, and you will get a general idea.

I looked over your code, and I got scrambled up (like you did with my code, I think). Not to be mean or anything, but I would like to learn one way, so can you please try to help using my code? If you didn't understand the code I had, just take a quick look through the tutorials I am learning from.
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

BUMP!

I really need help! Please take another look!
User avatar
mandai
Coding God
Coding God
Posts: 2585
Joined: Mon Apr 26, 2010 6:51 pm

Is there any particular advantage in following the other method?
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

I don't really wanna learn another way :P

Seriously though, I already learnt the way I said, and if I learn another way in my beginner steps in database programming, I'll become confused.
GoodGuy17
Coding God
Coding God
Posts: 1610
Joined: Mon Sep 07, 2009 12:25 am

Does anyone know how to help?
9 posts Page 1 of 1
Return to “Coding Help & Support”