CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Apr 2002
    Location
    Greece
    Posts
    42

    Insert into/update a database using MSRDC but not with SQL

    Hello.
    I'm making a program which connects to a MySQL dtabase, reads some tables, and populates comboboxes. The user fills a form with the comboboxes and textboxes and I'm ready to update the database.
    I want to use an MSRDC control but I don't want to use an SQL command because the database has an Auto Inc Key which I want to retrieve after I update the database (also it should be faster).
    So far I have this:

    Form1.MSRDCSpot.Connect = ConnectionString
    Form1.MSRDCSpot.Refresh

    which works perfectly if I want to read from the database, but when I write

    MSRDCSpot.BeginTrans

    it replies "The connection is not open".
    Can anyone give me an example as i can't find anything on the internet (without the use of SQL commands).
    Thanks.
    Visit www.greekroms.net

    Greek translations of roms

  2. #2
    Join Date
    Sep 2000
    Location
    FL
    Posts
    1,452

    Re: Insert into/update a database using MSRDC but not with SQL

    Although I cannont help you with MSRDC, you can most certainly use an Insert command with MySQL then get the Auto Inc field.

    If you do...

    INSERT INTO MyTable (Name, DOB) VALUES ('SoToasty', '2005-01-01');

    Followed by,

    SELECT last_insert_id() as ID;

    You will get back the AutoIncrement field from MySQL. The last_insert_id() function works on a per connection basis, so if you have more than one connection you can insert into multiple tables, and then use last_insert_id() to retrieve the ID from Multiple tables.

    I don't know if this will help you but it is all I can offer.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured