SAP Business One客户端中的运行时错误

时间:2019-09-21 10:46:39

标签: c# sap

我的代码有运行时错误 错误:

  

MatrixFill.exe中发生类型'System.Runtime.InteropServices.COMException'的异常,但未在用户代码中处理   附加信息:1)。 [Microsoft] [SQL Server Native Client 11.0] [SQL Server]'OCRD'附近的语法不正确。   我想通过C#连接到SAP并填充矩阵   如何更改代码????

我的代码:

using System;
using System.Collections.Generic;
using System.Xml;
using SAPbouiCOM.Framework;

namespace MatrixFill
{
  [FormAttribute("MatrixFill.Form1", "Form1.b1f")]
  class Form1 : UserFormBase
  {
    public Form1()
    {
    }

    /// <summary>
    /// Initialize components. Called by framework after form created.
    /// </summary>
    public override void OnInitializeComponent()
    {
      this.Matrix0 = ((SAPbouiCOM.Matrix)(this.GetItem("Item_0").Specific));
      this.Button0 = ((SAPbouiCOM.Button)(this.GetItem("btnFill").Specific));
      this.Button0.ClickBefore += new
      SAPbouiCOM._IButtonEvents_ClickBeforeEventHandler(this.Button0_ClickBefore);
      this.OnCustomInitialize();

    }

    /// <summary>
    /// Initialize form event. Called by framework before form creation.
    /// </summary>
    public override void OnInitializeFormEvents()
    {
    }

    private SAPbouiCOM.Matrix Matrix0;

    private void OnCustomInitialize()
    {

    }

    private SAPbouiCOM.Button Button0;

    private void Button0_ClickBefore(object sboObject, SAPbouiCOM.SBOItemEventArg pVal, out bool BubbleEvent)
    {
      BubbleEvent = true;
      SAPbobsCOM.Company oCompany = (SAPbobsCOM.Company)Application.SBO_Application.Company.GetDICompany();
      SAPbobsCOM.Recordset oRset = (SAPbobsCOM.Recordset)oCompany.GetBusinessObject(SAPbobsCOM.BoObjectTypes.BoRecordset);
      string Query = "select CardCode,CardName,E_Mail sFrom OCRD";
      oRset.DoQuery(Query);
      if (oRset.RecordCount > 0)
      {
        for (int i = 0; i < oRset.RecordCount; i++)
        {
          Matrix0.AddRow();
          ((SAPbouiCOM.EditText)Matrix0.Columns.Item("colCode").Cells.Item(i + 1).Specific).Value = oRset.Fields.Item("CardCode").Value.ToString();
          ((SAPbouiCOM.EditText)Matrix0.Columns.Item("colName").Cells.Item(i + 1).Specific).Value = oRset.Fields.Item("CardName").Value.ToString();
          ((SAPbouiCOM.EditText)Matrix0.Columns.Item("colEmail").Cells.Item(i + 1).Specific).Value = oRset.Fields.Item("E_Mail").Value.ToString();
          oRset.MoveNext();

        }
      }

    }
  }
}

注意: 我的表单有一个三列矩阵 该矩阵是在Visual Studio 2015中设计的

1 个答案:

答案 0 :(得分:0)

这是因为您在底部附近之前有s。

更改此

从OCRD中选择CardCode,CardName,E_Mail

从OCRD选择CardCode,CardName,E_Mail

欢呼

乔恩