on 12-07-2005 3:47 PM
I created a Usertable with the fields Descript, Locked, and TEST.(Code and Name are default)
I created a function to add values to the usertable:
public string addData(string code, string name, System.Collections.Hashtable hTable)
{
oCompany.StartTransaction();
System.Console.WriteLine("Add Record to Table("tableName")");
SAPbobsCOM.UserTable userTable = oCompany.UserTables.Item(tableName);
if(userTable.GetByKey(code) == false)
{
userTable.Code = code;
userTable.Name = name;
foreach(System.Collections.DictionaryEntry dEntry in hTable)
{
try
{
userTable.UserFields.Fields.Item("U_"+dEntry.Key).Value = dEntry.Value;
}
catch(System.Exception ex)
{
System.Console.WriteLine("Exception: "+ex.ToString());
throw ex;
}
}
/*foreach(string key in hTable.Keys)
{
userTable.UserFields.Fields.Item("U_"+key).Value = hTable[key];
}*/
if(userTable.Add() != 0) throw new COR_DBException("Data in Table "tableName" not added: "+oCompany.GetLastErrorDescription(), oCompany.GetLastErrorCode());
System.Console.WriteLine("Record added to Table("tableName")");
int w = userTable.Update();
System.Console.WriteLine("update: "+w);
}
else
{
throw new COR_DBException("Record already exists!");
}
oCompany.EndTransaction(SAPbobsCOM.BoWfTransOpt.wf_Commit);
userTable = null;
System.GC.Collect();
return oCompany.GetNewObjectKey();
}
My function call looks like that:
try
{
COR_ITable utStatus= new COR_UserTable("COR_PRJS");
Hashtable hTable = new Hashtable();
hTable.Add("Descript", "The Project ...");
hTable.Add("Locked", "Y");
hTable.Add("TEST", 12635);
utStatus.addData("10", "name0", hTable);
hTable.Clear();
hTable.Add("Descript", "The Project ...");
hTable.Add("Locked", "Y");
hTable.Add("TEST", 12235);
utStatus.addData("11", "name1", hTable);
}
catch(COR_Exception ex)
{
MessageBox.Show(ex.ToString());
System.Console.WriteLine(ex.ToString());
}
}
The Problem now is follow:
After the function call i find follow datas in database:
Code Name Description Locked TEST
10 name0 The Project... Y 12635
11 name1 The Project... Y
The second value by de Test-Field is missing(???)
When I add a new userField TEST3 at the end of the table and try the same function call it looks like this:
Code Name Description Locked TEST TEST3
10 name0 The Project... Y 12635
11 name1 The Project... Y 12235
I see the second value in the column TEST now. That can not be a solution?
But, this is not all. When i do now a second call with other values, i have the follow result:
Code Name Description Locked TEST TEST3
10 name0 The Project... Y 12635
11 name1 The Project... Y 12235
12 name2
13 name3
Now only Code and Name are filled in the database.
The Hashtable in the function addData is ok. In Debug-Mode I see all right values, but they are not filled in the database by the SAP function.
Can anybody help me?
I "solved" the problem! The problem is the function userTable.GetByKey(code). I tested with this function if the record already exists. When I remove this call all works fine.
public string addData(string code, string name, System.Collections.Hashtable hTable)
{
System.Console.WriteLine("Add Record to Table("+tableName+")");
SAPbobsCOM.UserTable userTable = oCompany.UserTables.Item(tableName);
//if(userTable.GetByKey(code) == false)
//{
userTable.Code = code;
userTable.Name = name;
foreach(System.Collections.DictionaryEntry dEntry in hTable)
{
userTable.UserFields.Fields.Item("U_"+dEntry.Key).Value = dEntry.Value;
}
if(userTable.Add() != 0) throw new COR_DBException("Data in Table "+tableName+" not added: "+oCompany.GetLastErrorDescription(), oCompany.GetLastErrorCode());
System.Console.WriteLine("Record added to Table("+tableName+")");
//}
//else throw new COR_DBException("Record already exists!");
return oCompany.GetNewObjectKey();
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
User | Count |
---|---|
95 | |
11 | |
11 | |
6 | |
6 | |
4 | |
4 | |
3 | |
3 | |
3 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.