?
Solved

saving into an access table, using oledbdataadapter

Posted on 2007-10-04
2
Medium Priority
?
414 Views
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 :
con.open()
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)

0
Comment
Question by:Mahdi Mansour
2 Comments
 
LVL 10

Accepted Solution

by:
ericwong27 earned 250 total points
ID: 20013711
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

        Try
            With cmd
                .Connection.Open()
                .ExecuteNonQuery()
                .Connection.Close()
            End With
        Catch ex As Exception
        End Try
0
 
LVL 1

Author Comment

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

Featured Post

Configuration Guide and Best Practices

Read the guide to learn how to orchestrate Data ONTAP, create application-consistent backups and enable fast recovery from NetApp storage snapshots. Version 9.5 also contains performance and scalability enhancements to meet the needs of the largest enterprise environments.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article describes a method of delivering Word templates for use in merging Access data to Word documents, that requires no computer knowledge on the part of the recipient -- the templates are saved in table fields, and are extracted and install…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
In Microsoft Access, learn the trick to repeating sub-report headings at the top of each page. The problem with sub-reports and headings: Add a dummy group to the sub report using the expression =1: Set the “Repeat Section” property of the dummy…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…
Suggested Courses

862 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