newbie question about adding a record to Access DB with VWD 2005

I am new to VWD 2005 and doing some learning. I am using Visual Basic as the language. I have a pretty simple Access DB that I am connected to. I can Edit and Delete records fine. However, I cannot find how to be able to add records to the database with VWD2005. Any assistance or pointing to a good tutorial would be greatly appreciated. I am thinking there is a simple way to do this, but I am just missing it.

Flanman




Answer this question

newbie question about adding a record to Access DB with VWD 2005

  • martinlooker

    Here is a link to some database examples that might help you get going:

    http://msdn.microsoft.com/vbasic/downloads/code/101samples/

    Either download all of the samples or go to the Data Access samples and download those. If you already have the Access DB the Data Sources Wizard should be able to create Add, Delete & Update for you.

    Check out this Channel 9 Video to get some ideas on using VB Express for creating databases : http://channel9.msdn.com/showpost.aspx postid=138769

    There is a ton of good info in Help too. If you have not done so yet, download and install the Dotnet Framework 2.0 SDK. It's a large download ( 330+ Megs) but, contains a lot of useful info and samples that can be of help to you.

    As a previous poster showed you, it is really better to code everything you can instead of relying on one of the Wizards to do it for you. One reason being, you will understand what is going on better and will have more control over the proccess. And the Wizards are not foolproof. Problems can creep into the code and it can be tough to debug the problem if you are not familiar enough with the methods being created to know where to start looking for problems. Error handling in VB 2005 is way better than it has been in the past, but, still there are things that can look perfectly logical and still not work.

    Good luck and keep asking questions. That is how I learn things. (something new everyday it seems!!)

    james

    aka:Trucker


  • Daniel Hawkins

    that routine is worth it's weight in gold.

    That's why I copied and saved your code for persisting an Access Database!!

    james

    aka:Trucker


  • xty

    Weeks and weeks and weeks of heavy duty people scratching their heads over that.

    It is indeed worth it's weight in gold. That's how I will write a primitive. It's flexible and very easy to develop with.

    I almost hated to post it because it really took a lot to get it right.



  • AshSingh007

     

    There are a million ways to do this depending upon how you have set up your datastructures. I can provide a way, but it may not match your datastructures

     

    Let’s say that you have a table called CurrentTable. To create a new record first of all you need a new data row.

     

    Dim row as  Datarow = Currenttable.NewRow

     

    You fill in all fields in the row… for illustration:

     

    Dim d As DataRow = CurrentTable.NewRow

            d(DataRecords.csOwningCategory) = lvO.OwningCategory

            d(DataRecords.csRecordType) = RecordType.csTopic

            d(DataRecords.CsName) = lvO.TopicName

            d(DataRecords.csAuthor) = ""

            d(DataRecords.csLevel) = lvO.Level

            d(DataRecords.csNode) = 0

            d(DataRecords.cdtDateCreated) = Date.Now

            d(DataRecords.cdtDateModified) = Date.Now

            d(DataRecords.ciDescriptor) = 0

            d(DataRecords.cbDocument) = System.Text.Encoding.Unicode.GetBytes(DirectCast(lvO, LvElementDesc).Document)

     

     

    Then I persist the database:

     

            adodb.PersistTable(CurrentTable, d)

     

    Where:

    Adapter is a member variable previously declared as:

    Public Adapter As OleDb.OleDbDataAdapter

     

    Public Function PersistTable(ByVal Table As DataTable, Optional ByVal NewRow As DataRow = Nothing) As Boolean

     

     PersistTable = False

            Adapter.SelectCommand = New OleDbCommand("Select * from [" & Table.TableName & "]", con)

            Dim builder As New OleDbCommandBuilder(Adapter)

            builder.QuotePrefix = "["

            builder.QuoteSuffix = "]"

     

            If NewRow IsNot Nothing Then

                NewRow.Item(DataRecords.ciRecordNo) = Table.Rows.Count

                Table.Rows.Add(NewRow)

            End If

     

            Try

     

                Adapter.Update(Table)

            Catch e As Exception

                MsgBox("Error persisting Table: " + Table.TableName + vbCrLf + "Exception was: " + e.Message, _

                        MsgBoxStyle.Information, "ADONET.PersistTable")

               End Try

            PersistTable = True

        End Function

     

    I have to admit, I  the PersistTable routine as it's pretty flexible and I use it for everything.

     

     

    I hope this helps….

     

     Renee

     

     



  • Newton6

    Ok.. so I see you are doing it with some manual coding. Does that mean there is no ''Automatic" way of VWD creating an add option. I figured since it creates the Update and Delete fuctions on the fly it would add the "Add" fuctionality as well.

  • walter_verhoeven

    As a previous poster showed you, it is really better to code everything you can instead of relying on one of the Wizards to do it for you.

    Exactly!!!!!!!! I Never use a wizard... I hand code everything. It takes longer but you have so much more control and don;t paint yourself into a corner.

    I can't tell you how long it took me to get the routine right. It ook weeks. People scrached their heads over persisting Access databases for quite a while. But once I got that... it's nver let me down and that routine is worth it's weight in gold.



  • AJAX

    ReneeC wrote:

    Weeks and weeks and weeks of heavy duty people scratching their heads over that.

    It is indeed worth it's weight in gold. That's how I will write a primitive. It's flexible and very easy to develop with.

    I almost hated to post it because it really took a lot to get it right.

    I can understand your hesitation, but, I'm also glad you decided to share. I'm in the middle of an Access DB project myself and this will certainly provide some insight into persistance. As I said earlier, I manage to learn something new every day.

    Thanks to people willing to share, such as yourself.

    james

    aka:Trucker


  • newbie question about adding a record to Access DB with VWD 2005