Page 1 of 1

Inserting a record in another table after adding

Posted: Fri Dec 16, 2016 3:50 pm
by vlietinho

I need to create an empty stock (voorraad) record after inserting an article record.

So in the Row_Inserted event of the Article table I have:

string sInsertSql = "INSERT INTO Voorraad (artikelnummer, locatie, aantal) VALUES ([Artikelen.Artikelnummer], 'EM', 0)";
ew_Execute(sInsertSql);

But Artikelen.Artikelnummer is not recognized.
I tried x_Artikelnummer and some other things, but I can't get it to work.

What should I use there? (I'm new to this ;-) )

Thx


Re: Inserting a record in another table after adding

Posted: Sat Dec 17, 2016 11:03 am
by motfs

"INSERT INTO Voorraad (artikelnummer, locatie, aantal) VALUES ([Artikelen.Artikelnummer], 'EM', 0)";

If you want to insert a value from the inserted record, use rsnew["<fieldname>"] instead of [Artikelen.Artikelnummer]. Otherwise, explain in detail what you try to do.


Re: Inserting a record in another table after adding

Posted: Mon Dec 19, 2016 3:55 pm
by vlietinho

Thx for the reply, I do indeed want to insert a value from the inserted record in another table, but I still can't get this to work.

When I try what you suggest, I get an error during compilation :

Artikeleninfo.cs(1091,95):Error CS1002 ; expected
Artikeleninfo.cs(1091,108):Error CS1002 ; expected

I used this:
string sInsertSql = "INSERT INTO Voorraad (artikelnummer, locatie, aantal) VALUES (rsnew["Artikelnummer"], 'EM', 0)";
ew_Execute(sInsertSql);

After that I've tried to use single quote's (rsnew['Artikelnummer']), then the page does compile, however I get an error on the page after adding (Incorrect syntax near ''Artikelnummer''.)

This is the whole piece:

// Row Inserted event
public void Row_Inserted(OrderedDictionary rsold, OrderedDictionary rsnew) {
//ew_Write("Row Inserted");
// Insert record
// NOTE: Modify your SQL here, replace the table name, field name and field values
string sInsertSql = "INSERT INTO Voorraad (artikelnummer, locatie, aantal) VALUES (rsnew['Artikelnummer'], 'EM', 0)";
ew_Execute(sInsertSql);
}


Re: Inserting a record in another table after adding

Posted: Tue Dec 20, 2016 5:01 pm
by vlietinho

FYI, I got it working ;-)

Code:

string sArtikel;
sArtikel = (string)rsnew["Artikelnummer"];
string sInsertSql = "INSERT INTO Voorraad (artikelnummer, locatie, aantal) VALUES ('" + sArtikel + "', 'EM', 0)";
ew_Execute(sInsertSql);