You can either try creating multiple export settings in document definition for each table, or create a custom export script.
Regards Timur
0
Permanently deleted user
Hi Timur, Many thanks for your kind reply. Can u please share some export script in C# ?
kind regards ibrar shah
0
Permanently deleted user
Hello,
Heres is an example of a custom export to database
using System.Data; using System.Data.OleDb; string ConnectionString = connectionString; OleDbConnection Con = new OleDbConnection(ConnectionString); \\-> connection string to your database try { \\-fields you want export string ID = Document.Properties.Get("ID"); string NUM = Document.Field("Document defintion name\\NUM").Text;
\\open conncetion to DB Con.Open();
using (OleDbCommand cmd = Con.CreateCommand()) { \\insert query cmd.CommandText = string.Format("INSERT INTO SomeDBTable (ID,NUM) VALUES" + "(?,?)");
\\insert values to query cmd.Parameters.AddWithValue("@ID", ID); cmd.Parameters.AddWithValue("@NUM", NUM);
\\execute command int rows = cmd.ExecuteNonQuery();
This is just an example and it needs to be adjusted according to your needs. You can also consider using ODBC connection or System.Data.SqlClient instead of Oledb connection.
And also, you will need to add an additional insert query in order to add data to multiple tables.
Since you need to perform two queries, best practice is to execute them inside a Transaction (OleDbTransaction class), by doing so if one the queries fails all changes are rolled back.
Comments
5 comments
You can either try creating multiple export settings in document definition for each table, or create a custom export script.
Regards
Timur
Many thanks for your kind reply. Can u please share some export script in C# ?
kind regards
ibrar shah
Heres is an example of a custom export to database
using System.Data;
using System.Data.OleDb;
string ConnectionString = connectionString;
OleDbConnection Con = new OleDbConnection(ConnectionString); \\-> connection string to your database
try
{
\\-fields you want export
string ID = Document.Properties.Get("ID");
string NUM = Document.Field("Document defintion name\\NUM").Text;
\\open conncetion to DB
Con.Open();
using (OleDbCommand cmd = Con.CreateCommand())
{
\\insert query
cmd.CommandText = string.Format("INSERT INTO SomeDBTable (ID,NUM) VALUES" +
"(?,?)");
\\insert values to query
cmd.Parameters.AddWithValue("@ID", ID);
cmd.Parameters.AddWithValue("@NUM", NUM);
\\execute command
int rows = cmd.ExecuteNonQuery();
Processing.ReportMessage("Export successfull, RowsCount=" + rows);
}
}
catch (Exception e)
{
Processing.ReportError(e.ToString());
}
finally
{
Con.Close();
}
This is just an example and it needs to be adjusted according to your needs.
You can also consider using ODBC connection or System.Data.SqlClient instead of Oledb connection.
And also, you will need to add an additional insert query in order to add data to multiple tables.
Since you need to perform two queries, best practice is to execute them inside a Transaction (OleDbTransaction class), by doing so if one the queries fails all changes are rolled back.
Regards,
Timur
Many thanks for your quick response .
kind regards
ibrar shah
Please sign in to leave a comment.