Web Services 使用Web服务写入数据集

qgzx9mmu  于 2022-11-15  发布在  其他
关注(0)|答案(1)|浏览(137)

我需要将一些简单的数据写入数据集www.example.com Web服务中已经存在的表中using.net,但是它给了我以下错误。

System.MissingMethodException: No parameterless constructor defined for this object.
   at System.RuntimeTypeHandle.CreateInstance(RuntimeType type, Boolean publicOnly, Boolean noCheck, Boolean& canBeCached, RuntimeMethodHandleInternal& ctor, Boolean& bNeedSecurityCheck)
   at System.RuntimeType.CreateInstanceSlow(Boolean publicOnly, Boolean skipCheckThis, Boolean fillCache, StackCrawlMark& stackMark)
   at System.Activator.CreateInstance(Type type, Boolean nonPublic)
   at System.Activator.CreateInstance(Type type)
   at System.Web.Services.Protocols.ServerProtocol.CreateServerInstance()
   at System.Web.Services.Protocols.WebServiceHandler.Invoke()
   at System.Web.Services.Protocols.WebServiceHandler.CoreProcessRequest()

下面是我尝试过的代码。

public class DataSave : System.Web.Services.WebService
    {
        DataSet DS = new DataSet();
        DataSet _dataset;

        public DataSave(DataSet dataSet)
        {
            _dataset = dataSet;
        }

        [WebMethod]
        public void SubmitStudents()
        {
            DataSet.StudentsRow row = _dataset.Students.NewStudentsRow();
            row.Name = "Sam";
            row.Age = 5;
            row.School =  "PreSchool";
            row.Date = DateTime.Today;
            this._dataset.Students.Rows.Add(row);
        }
    }
}

是什么原因导致此错误?

gopyfrb3

gopyfrb31#

请尝试以下操作:

public class DataSave 
    {

        DataSet _dataset= new DataSet();
        DataTable _dt = new DataTable();
        

        public DataSave(DataSet dataSet)
        {
            _dataset.Tables.Add(_dt);
            _dt.Columns.Add("Name",typeof(string));
            _dt.Columns.Add("Age",typeof(int));
            _dt.Columns.Add("School",typeof(string));
            _dt.Columns.Add("Data",typeof(DateTime));
        }

        public void SubmitStudents()
        {
            DataRow row = _dt.Rows.Add(new object[] {"Sam", 5, "PreSchool", DateTime.Today);
        }
    }

相关问题