• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 140
  • Last Modified:

Writing Data into Access Using ADO.Net

Hi All,

Im using ADO.Net in my app to read data from an Access database. I'm OK doing this but I'm unsure how to write data back into Access with ADO.Net as I am used to using ADOdb.
Can someone give me a quick example.
Thanks
0
kiranboi
Asked:
kiranboi
  • 2
1 Solution
 
Ajay SharmaCommented:
declare this

Public myConnection As OleDbConnection

Public ConnStr As String = "PROVIDER=Microsoft.Jet.OLEDB.4.0;DATA SOURCE=" & System.Web.HttpContext.Current.Server.MapPath("") & "/db.mdb;"



then in the webform import this
Imports System.Data.OleDb

on the insert button click put this

Try
                    Dim SQL As String
                    Dim comm As OleDbCommand
                    myConnection = New OleDbConnection(ConnStr)
                    myConnection.Open()

                    SQL = "insert into tblNewsletter (emailid, createdon) values ('" & somveVar  & "','" & Now & "')"

                    comm = New OleDbCommand(SQL, myConnection)
                    comm.ExecuteNonQuery()
                    myConnection.Close()
                Catch ex As Exception
                   'Response.Write(ex.Message)
                End Try
0
 
kiranboiAuthor Commented:
just out of interest, is there any way of doing it without using SQL?
0
 
kiranboiAuthor Commented:
can you show me an example of updating a record and one of creating a new record and deleteing one
thanks
0
 
Priest04Commented:
Yes, since you say you already know how to fetch data, you just need to add oledbcommandbuilder to generate InsertCommand, UpdateCommand and DeleteCommd for DataAdapter can know how to update data in database. See this link

http://msdn2.microsoft.com/en-us/library/system.data.oledb.oledbcommandbuilder.aspx

Goran
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now