SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2001
    Posts
    2
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    how to insert record using ado ?

    how to insert or delete record from table using ado ?

    i use the following to select records.

    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open "e:/domains/aass.com/user/htdocs/asp/VBQUIZ.mdb"
    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open "Select * from quiz", conn
    %>

  2. #2
    SitePoint Wizard
    Join Date
    Jan 2001
    Location
    Milton Keynes, UK
    Posts
    1,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Have a look at some of the articles/scripts at the following links.

    http://www.asp101.com/samples/db_del.asp
    http://www.learnasp.com/learn/dbSQLdelete.asp
    http://www.learnasp.com/learn/dbnewSQL.asp
    http://www.learnasp.com/learn/dbnewADO.asp

    If you get stuck post your questions in the ASP/Cold Fusion forum and I'm sure one of us will be able to help.

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2001
    Posts
    39
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey,
    You can try using simply an ADODB.Connection:

    dim objConn
    set objConn = Server.CreateObject("ADODB.Connection")

    'To access an SQL Server
    objConn.Open "Provider=SQLOLEDB; Data Source = localhost; Initial Catalog = MyDatabase; User Id = sa; Password = "

    objConn.Execute "INSERT INTO myTable(id, name, age) VALUES(1, 'Mitchell', 19)"

    You should search for articles on the INSERT function if you aren't too familiar with SQL syntax.
    SiteTell.com: Get the best viral marketing tool on the planet and watch as the number of unique visitors to your site soars!

  4. #4
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You could also use the AddNew and Update methods on your recordset object to add a record.

    set conn=Server.CreateObject("ADODB.Connection")
    conn.Provider="Microsoft.Jet.OLEDB.4.0"
    conn.Open "e:/domains/aass.com/user/htdocs/asp/VBQUIZ.mdb"
    set rs=Server.CreateObject("ADODB.recordset")
    rs.Open "Select * from quiz", conn

    rs.AddNew ' adds a new record
    rs("[field name]") = [new value] 'edits field value
    rs.Update 'Commits change
    %>

    Sometimes this is more convenient than SQL, although learning SQL is usually preferable in my opion since you can then talk to just about any database.

    To delete a record you could use the Delete method

    select a record
    rs.Delete

  5. #5
    SitePoint Enthusiast
    Join Date
    Jun 2001
    Posts
    87
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I might and should add that using the recordset.AddNew method can slow things down since all the records are brought into memory in the recordset whereas by using SQL INSERT no recordset is created.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •