Inserting a record in another table after adding

This public forum is for user-to-user discussions of ASP.NET Maker. Note that this is not support forum.
Post Reply
vlietinho
User
Posts: 4

Inserting a record in another table after adding

Post 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


motfs
User
Posts: 258

Post 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.


vlietinho
User
Posts: 4

Post 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);
}


vlietinho
User
Posts: 4

Post 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);

Post Reply