ASP.Net MVC3连接SAP实践

[csharp]    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.Mvc;
    using SAP.Middleware.Connector;
    using System.Data;
    namespace SAPMVC.Controllers
    {
    public class HomeController : Controller
    {
    string MATNR = string.Empty;
    public ActionResult Index()
    {
    ViewBag.Message = "Welcome to ASP.NET MVC!";
    nco();
    //nco2();
    return View();
    }
    public void nco2()
    {
    RfcConfigParameters rfcPar = new RfcConfigParameters();
    //rfcPar.Add(RfcConfigParameters.Name, "CON");
    //rfcPar.Add(RfcConfigParameters.AppServerHost, "192.168.1.3");
    //rfcPar.Add(RfcConfigParameters.Client, "800");
    //rfcPar.Add(RfcConfigParameters.User, "UserID");
    //rfcPar.Add(RfcConfigParameters.Password, "Password");
    //rfcPar.Add(RfcConfigParameters.SystemNumber, "02");
    //rfcPar.Add(RfcConfigParameters.Language, "EN");
    rfcPar.Add(RfcConfigParameters.Name, "CON");
    rfcPar.Add(RfcConfigParameters.AppServerHost, "192.168.1.3");   //SAP主机IP
    rfcPar.Add(RfcConfigParameters.SystemNumber, "00");  //SAP实例
    rfcPar.Add(RfcConfigParameters.User, "MENGXIN");  //用户名
    rfcPar.Add(RfcConfigParameters.Password, "5239898");  //密码
    rfcPar.Add(RfcConfigParameters.Client, "888");  // Client
    //rfcPar.Add(RfcConfigParameters.Language, "ZH");  //登陆语言
    //rfcPar.Add(RfcConfigParameters.PoolSize, "5");
    //rfcPar.Add(RfcConfigParameters.MaxPoolSize, "10");
    //rfcPar.Add(RfcConfigParameters.IdleTimeout, "60");
    RfcDestination dest = RfcDestinationManager.GetDestination(rfcPar);
    RfcRepository rfcrep = dest.Repository;
    IRfcFunction myfun = null;
    myfun = rfcrep.CreateFunction("SAP里面的函数名称");
    myfun.SetValue("VTYPE", "0");//SAP里面的传入参数
    myfun.Invoke(dest);
    IRfcTable IrfTable = myfun.GetTable("IT_ZMYTB2");
    //提前实例化一个空的表结构出来
    DataTable dt = new DataTable();
    dt.Columns.Add("USERID");
    dt.Columns.Add("USERPWD");
    dt.Columns.Add("USERADDRESS");