Script Insert to SQL Server?

How to write script insert to sql server when cilck button


Hello captain,

First you need to create a Datasets > Queries like the one below:
image

Then in Draw you create a button, double click in this object and it will open a window like this, and click in “New”
image

It will open in CodeBehind a new method that will be executed every time you click in the button.
In this method you can add this line to do a SELECT command:
@Dataset.Query.Query1.SelectCommand();

For other statements like INSERT, UPDATE… you can use like this:
@Dataset.Query.Query1.ExecuteCommand();

If you want to edit the SQLStatement in runtime, you can use this line
@Dataset.Query.Query1.SqlStatement = "<SQLStatement>";

Hope this helps, if you need anything else let us know please.

Best Regards,
Eduardo.

Hi, im having same issue with my insert query.
An initialize error and Invalid Handle message are showing on Trace Window.
I double check the connection string in Dataset/DBs and the test says “Ok”.
My script is:
@Dataset.Query.Query2.SqlStatement = “INSERT INTO EventosMaquina3 (idEquipo, estado) VALUES (100, 1)”;
@Dataset.Query.Query2.ExecuteCommandAsync();
What im missing here?

Hello oscmel,
This problem seams to be related to the SQL Connection itself, and not to the Insert Command.
What is the type of DataBase connection you’re making in this solution?
Are you able to access the contents inside this DataBase?
Has this connection ever worked, or is this the first time you’re setting it up?
and lastly, what’s your software’s (FactoryStudio or FramerworX) version?

Best Regards,
Lucas

Im using sqlClient but tried with oledb too. and same result.
Here an image of the connection.
Im using Frameworx update 1c

if i execute the insert query in the Data explorer/SQL Queries it shows an error message “Object reference not set to an instance of an object” but in my table i see the new records inserted. But this only with Data explorer.

i tried with make a Table in Datasets too and execute the .INSERT = 1 but shows “Invalid Handle”.

Yes, im able to access the data with sql server managment studio, and i can make a SELECT Query and have results from Data explorer.

I just prepare a new windows 10 virtual machine only with sql server 2016 and frameworx but have same result.

This seems quite unexpected, as I was able to make a table on SQLServer with the same table as yours, using the exact same command and it worked all fine.
For this, it might be better to contact support as they can further help you in meetings, ask for more details and give you more attention overall.