cancel
Showing results for 
Search instead for 
Did you mean: 

How to insert data in the table?

Former Member
0 Kudos

I created a table called @PTSFCT in SB1. Now I would like to insert data in the fields of the table. How can I do it?

Accepted Solutions (0)

Answers (2)

Answers (2)

Former Member
0 Kudos

On Insert data I don´t use select. How to Updat a register in the table?

Former Member
0 Kudos

Hi.

Is You can`t update them with an object, You can use RecordSet.

Here is some code in C++:


SAPbobsCOM::IRecordSetPtr record;
record=m_Cmp->GetBussinessObject(SAPbobsCOM::boRecordSet);
//m_Cmp - is the company object;
_bstr_t m_Query;

m_Query = L"insert into [@table] (field1, field2...) values (value1, value2...)";
long ret;
ret = record->DoQuery(m_Query);

You can use Select, Update, Insert, Delete in m_Query (String).

Check ret code - if =0 then all is ok, else use:


m_cmp->GetLastError(*long, *BSTR);

Sorry for my english.

Hope it helps.

Kamil Wydra.

former_member185703
Active Contributor
0 Kudos

Hi Kamil,

Thank you very much for your engagement - obviously I had overlooked the question regarding updates...)!

...BUT:

You can use the Update() (Remove() exists as well) method of the UserTable object.

However, developers have the freedom to choose the update / insert / delete of UDTs using SQL at the cost of some DB dependency (DB2 is a bit different in handling UDTs ASFAIK).

Regards,

Frank

former_member184566
Active Contributor
0 Kudos

Hi

Here is an example, im assuming you want to do it through the sdk.

Dim oUserTable As SAPbobsCOM.UserTable

'Use the user table we added before

oUserTable = oCompany.UserTables.Item("SOS_OENQ")

'Add a first row in the table

oUserTable.Code = Value

oUserTable.Name = Value

oUserTable.UserFields.Fields.Item("U_ComName").Value = CompanyName

oUserTable.UserFields.Fields.Item("U_ComTel").Value = CompanyTel

oUserTable.UserFields.Fields.Item("U_CntName").Value = ContactName

oUserTable.UserFields.Fields.Item("U_CntTel").Value = ContactTel

oUserTable.UserFields.Fields.Item("U_Brnch").Value = oCombo.Selected.Value

lRetCode = oUserTable.Add

You must check lretcode, it should be zero, if not it means it was not successfull.

Hope this helps

Former Member
0 Kudos

I tried to use the code that you sent me but I do not have oCompany and lRetCode declared. How I must declare them?

Former Member
0 Kudos

oCompany is the SAPbobsCOM.company class. declare as

<b>SAPbobsCOM.Company oCompany; (C#)</b>

lRetCode is a long interger for error handling... so simply:

<b>int iRetCode = 0; (C#)</b>

however before you use oCompany you have to connect the oCompany to the SBO of your choice... using the following block of code:

int lErrCode = 0;

int IRetCode = 0;

string sErrMsg = string.empty;

oCompany.Server = "Your server"; (if it's a local server then just put in "(local)")

oCompany.CompanyDB = "yourcompanydb" (for example SBODemo_US;

oCompany.UserName = "your SBO username"; (have to be administrator)

oCompany.Password = "you SBO password";

// Connecting to a company DB

lRetCode = oCompany.Connect();

if ( lRetCode != 0 )

{

oCompany.GetLastError( out lErrCode, out sErrMsg );

Application.MessageBox.Show("You got error: "+sErrMsg);

}

else {

Application.MessageBox.Show( "Connected to " + globals.oCompany.CompanyName);

}

A very good way to get all these informations are in the Sample files in the SDK.. provide both C#, VB.net and JAVA codes... I just started using SDK a month ago myself. The Samples files help me greatly!

Message was edited by: Bo Peng

former_member185703
Active Contributor
0 Kudos

Please download the SDK Helpcenter (available from the SAP Business One Developer Area) + go over the brief introductory sections - e.g. for DI API - so that you better know where to go/start.

...it even contains sample code snippets...

Please read the "SAP Business One Forum news... " thread:

=> Besides other links you will find a link where you can download the (basic) E-learning flashbooks for the B1 SDK.

Please check-out the SDK samples (as suggested by Bo).

Former Member
0 Kudos

with your help it is already possible to introduce data in the table that I created. But now I want to introduce some of the data in the table "OPOR" of the SP B1 but the data are not introduced in the table.