saving into an access table, using oledbdataadapter

Posted on 2007-10-04
Last Modified: 2013-12-25
i hava a table in access: element(ID,Name)
that i want to save data in from my form ..
this is wht i have in my command button :
dim instr as string
instr="insert into element(ID,Name) values (@ID,@Name)"
Da=new oledbdataadabter(instr,con)
da.insertcommand.parameters.add("@ID", textbox1.text)
da.insertcommand.parameters.add("@Name", textbox2.text)

Question by:Mahdi Mansour
    LVL 10

    Accepted Solution

    Try this
            Dim strConn As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\XXX.mdb"
            Dim strSQL As String = "insert into element(ID,Name) values (@ID,@Name)"
            Dim conn As New OleDbConnection(strConn)
            Dim cmd As New OleDbCommand(strSQL, conn)
            With cmd
                .Parameters.Add(New OleDbParameter("@ID", OleDbType.WChar, 10)).Value = TextBox1.Text
                .Parameters.Add(New OleDbParameter("@Name", OleDbType.WChar, 10)).Value = TextBox2.Text
            End With

                With cmd
                End With
            Catch ex As Exception
            End Try
    LVL 1

    Author Comment

    by:Mahdi Mansour
    it gave me an error on the add parameter line:
    "The oledbparameterCollection only accepts non-null oledbparameter type objects, not boolean objects"

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
    It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
    Familiarize people with the process of retrieving data from SQL Server using an Access pass-thru query. Microsoft Access is a very powerful client/server development tool. One of the ways that you can retrieve data from a SQL Server is by using a pa…
    What’s inside an Access Desktop Database. Will look at the basic interface, Navigation Pane (Database Container), Tables, Queries, Forms, Report, Macro’s, and VBA code.

    779 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now