第一次使用SAP B1。
我设法使用C#和SAP DI API版本9.00连接到SAP B1数据库并显示一个BP信息
我想要做的是显示所有BP或一个BP信息。在GridView中。
这是我的连接代码,完美无缺:
SAPbobsCOM.Company vCmp = new SAPbobsCOM.Company();
int lRetCode, lErrCode;
string sErrMsg;
vCmp.Server = "SAPR01";
vCmp.DbServerType = SAPbobsCOM.BoDataServerTypes.dst_MSSQL2008;
vCmp.CompanyDB = "company";
vCmp.UserName = "user";
vCmp.Password = "*****";
vCmp.language = SAPbobsCOM.BoSuppLangs.ln_English;
lRetCode = vCmp.Connect();
if (lRetCode == 0)
{
label1.Text = "Hello World!";
}
else
{
label1.Text = "Connection Failed!";
}
lErrCode = vCmp.GetLastErrorCode(); sErrMsg = vCmp.GetLastErrorDescription();
vCmp.GetLastError(out lErrCode, out sErrMsg);
这是我使用标签显示BP名称的代码:
SAPbobsCOM.BusinessPartners BP;
BP = vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.oBusinessPartners);
string cardName;
if (BP.GetByKey("C70000"))
{
cardName = BP.CardName;
label1.Text = cardName;
}
我无法弄清楚的是在Gridview中显示所有BP /一个BP信息。换句话说,如何绑定到Gridview?
谢谢!
答案 0 :(得分:1)
经过几个小时的搜索并尝试了很多代码,我设法显示了BP的信息。使用此代码:
SAPbobsCOM.SBObob obj = vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoBridge);
SAPbobsCOM.Recordset rs = vCmp.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
rs = obj.GetBPList(SAPbobsCOM.BoCardTypes.cCustomer);
rs.MoveFirst();
int count = rs.RecordCount;
grdBP.Rows.Clear();
if (count > 0)
{
grdBP.Columns.Add("cardCode", "BP Code");
grdBP.Columns.Add("cardName", "BP Name");
grdBP.Columns.Add("cardType", "BP Type");
grdBP.Rows.Add(count);
int gridCounter = 0;
while (!rs.EoF)
{
DataGridViewRow row = grdBP.Rows[gridCounter];
row.Cells[0].Value = rs.Fields.Item("cardCode").Value;
row.Cells[1].Value = rs.Fields.Item("cardName").Value;
row.Cells[2].Value = rs.Fields.Item("cardType").Value;
gridCounter++;
rs.MoveNext();
}
}
我必须手动创建我的列和行才能使用Recordset
我使用C#Windows Form。