Alpha Video Training
Results 1 to 7 of 7

Thread: How Can I add a new record using a Dialog component?

  1. #1
    Member
    Real Name
    Javier Jaramillo
    Join Date
    Jan 2006
    Posts
    9

    Default How Can I add a new record using a Dialog component?

    I need add a new user in my "LoginUser" table(MS Access - ADO connection) and I try to use a dialog component. My problem is when I try to use "INSERT INTO SQL statement" on Validate Event I have a message telling me "INSERT INTO syntax error". I have revised the examples available but none it was helpful. Can anybody give me any idea or light about it? Here I have my code:

    Code:
    dim connString as C
    dim conn as ole::adodb.connection
    
    'Open the connection
    connString = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=c:\database1\Memberships\Single User\Memberships.mdb;Persist Security Info=False"
    conn.open(connString)
    rs = conn.Execute("select * from LoginUser")
    
    dim sqlinsert as C
      
    sqlinsert = "INSERT INTO LoginUser (UserId, password) VALUES ('test2', 'test2')"
    
    ra = 0 
    conn.Execute(sqlinsert, ra)
    conn.close()
    Last edited by AaronBBrown; 01-27-2006 at 04:25 PM.

  2. #2
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,699

    Default

    Why not just use a grid? Then you don't have to worry about writing ADO code and getting the right SQL syntax.

  3. #3
    Alpha Software Employee AaronBBrown's Avatar
    Real Name
    Aaron Brown
    Join Date
    Feb 2001
    Location
    Waltham, MA
    Posts
    2,836

    Default

    To add to what Lenny said, you can use a Grid component set to a columnar layout with the number of displayed records = 0 and number of data entry rows = 1 and it will behave exactly like a dialog (they share the same code, in fact), except that it will be bound to a table.
    [FONT=Tahoma][SIZE=1][COLOR=Blue]Aaron Brown
    Alpha Software Development Team[/COLOR][/SIZE][/FONT]

  4. #4
    Member
    Real Name
    Javier Jaramillo
    Join Date
    Jan 2006
    Posts
    9

    Default I know using a grid is more simple but I need to .....

    Quote Originally Posted by Lenny Forziati
    Why not just use a grid? Then you don't have to worry about writing ADO code and getting the right SQL syntax.
    Lenny: The point is I need to send email confirmation to new membership. Using the dialog component should be easy include the code to send that email with the variables used in the dialog form. When I was trying with grid component I had difficulties to include the send email function on events.

  5. #5
    Alpha Software Employee Lenny Forziati's Avatar
    Real Name
    Lenny Forziati
    Join Date
    Nov 2001
    Location
    Alpha Software
    Posts
    4,699

    Default

    You should still be able to send an email fromt he grid event, many users are doing it. What problems were you having?

    Quote Originally Posted by javierjar
    Lenny: The point is I need to send email confirmation to new membership. Using the dialog component should be easy include the code to send that email with the variables used in the dialog form. When I was trying with grid component I had difficulties to include the send email function on events.

  6. #6
    Member
    Real Name
    Javier Jaramillo
    Join Date
    Jan 2006
    Posts
    9

    Default The definition of field names was the problem....

    Quote Originally Posted by Lenny Forziati
    You should still be able to send an email fromt he grid event, many users are doing it. What problems were you having?
    Lenny: I was trying to use afterupdateRecords event. When I try to define the fields of the record it didn't work. Can you refer me any documentation or sample how to accomplish it?

  7. #7
    Member pruel's Avatar
    Real Name
    Phil Ruel
    Join Date
    Dec 2005
    Posts
    85

    Default

    This snippet is actually working for me with a MySQL database. Some code was removed for clarity, so some declarations may seem silly since they're declared and immediately used as literals, but I hope it works for you. Oh, this was embedded in <%A5 %> on a .A5W page (thus the use of the "?" print operator and the error handling in general with currentForm), but should work in an event.
    Code:
    on error goto e_db
    
    dim conn as ole::adodb.connection
    
    conn.open("Provider=MSDASQL.1;Persist Security Info=False;Data Source=db")
    
    dim cmd as ole::adodb.command
    cmd.ActiveConnection = conn
    
    cmd.CommandText = "INSERT INTO cc (field1) VALUES ('field1 value')"
    dim ra as N
    ra = 0
    cmd.Execute(ra)
    
    if ra <> 1 then
    	currentForm.has_error = .t.
    	currentForm.error_message = "MySQL error: insert <> 1 rows.  Please report error."
    end if
    conn.close()
    goto done
    
    '
    '	Error handler
    '
    e_db:
    	? "Internal Database Error: " + error_text_get(error_code_get()) + ".  Please report error."
    	end
    done:
    Last edited by pruel; 02-02-2006 at 07:17 PM.

Similar Threads

  1. Error when saving dialog component
    By Louis Nickerson in forum Web Application Server v6
    Replies: 2
    Last Post: 12-17-2005, 08:22 AM
  2. Dialog Component with tabs
    By George Morley in forum Web Application Server v7
    Replies: 0
    Last Post: 11-01-2005, 11:28 AM
  3. Adv button in dialog component
    By Pat Bremkamp in forum Web Application Server v6
    Replies: 6
    Last Post: 10-25-2005, 09:47 PM
  4. Validate in Dialog Component
    By Louis Nickerson in forum Web Application Server v6
    Replies: 2
    Last Post: 03-06-2005, 06:57 AM
  5. first record add dialog
    By John Cunradi in forum Alpha Five Version 5
    Replies: 2
    Last Post: 09-19-2003, 11:59 AM

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
  •