Quantcast
Channel: SCN : All Content - All Communities
Viewing all articles
Browse latest Browse all 8735

Problem setting primary key

$
0
0

Hello,

 

I am using the following code to create my table in SBODemoUS database.  (Is a Test usage!) I create my table as SAPbobsCOM.BoUTBTableType.bott_MasterData.

 

var mensaje = string.Empty;            db.CrearTabla(textBox1.Text, "Huesest", SAPbobsCOM.BoUTBTableType.bott_MasterData, compania, out mensaje);            db.AgregarCamposTabla(compania, textBox1.Text, "id", "descripcion", SAPbobsCOM.BoFieldTypes.db_Numeric, 8, out mensaje);            db.AgregarCamposTabla(compania, textBox1.Text, "nombres", "descripcion", SAPbobsCOM.BoFieldTypes.db_Alpha, 120, out mensaje);            db.AgregarCamposTabla(compania, textBox1.Text, "apellidos", "descripcion", SAPbobsCOM.BoFieldTypes.db_Alpha, 120, out mensaje);            db.AgregarCamposTabla(compania, textBox1.Text, "direccion", "descripcion", SAPbobsCOM.BoFieldTypes.db_Alpha, 253, out mensaje);            db.AgregarCamposTabla(compania, textBox1.Text, "localizador", "descripcion", SAPbobsCOM.BoFieldTypes.db_Alpha, 200, out mensaje);

 

 

       public  void AgregarCamposTabla(SAPbobsCOM.Company oCompany, String nombretabla, String nombre,String descripcion,SAPbobsCOM.BoFieldTypes tipo, Int32 tamano, out String mensaje)        {            SAPbobsCOM.UserFieldsMD oUserFieldsMD = null;            mensaje = String.Empty;            oUserFieldsMD = ((SAPbobsCOM.UserFieldsMD)(oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oUserFields)));            oUserFieldsMD.TableName = nombretabla;            oUserFieldsMD.Name = nombre;            oUserFieldsMD.Description = descripcion;            oUserFieldsMD.Type = tipo;            oUserFieldsMD.EditSize = tamano;                        // Adding the Field to the Table            int lRetCode = oUserFieldsMD.Add();                       String sErrMsg = String.Empty;            if (lRetCode != 0)            {                    oCompany.GetLastError(out lRetCode, out sErrMsg);                    mensaje = sErrMsg;            }            else            {                mensaje = "El campo: '" + oUserFieldsMD.Name + "' fue agregado a la tabla " + oUserFieldsMD.TableName;            }                      GC.Collect();                   }

 

so I want to create a primary key.

 

 

 

db.CrearClavePrimaria(compania, textBox1.Text, "U_id", "U_id");
public void CrearClavePrimaria(SAPbobsCOM.Company oCompany, String nombretabla, String nombrekey, String alias)        {
UserKeysMD keyMd = (UserKeysMD)oCompany.GetBusinessObject(BoObjectTypes.oUserKeys);            keyMd.TableName = nombretabla;            keyMd.KeyName = nombrekey;            keyMd.Elements.ColumnAlias = alias;            keyMd.Unique = BoYesNoEnum.tNO;            int valor = keyMd.Add();            String sErrMsg = String.Empty;            if (valor != 0)            {                oCompany.GetLastError(out valor, out sErrMsg);                //mensaje = sErrMsg;            }
}

 

 

But this gave me error -5002 : Invalid field name

 

 

I test passing id, U_id, etc. this doesnt work.

 

Regards.


Viewing all articles
Browse latest Browse all 8735

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>