简体   繁体   English

强类型的数据集适配器更新不会插入新行

[英]Strongly typed dataset adapter update won't insert a new row

I have a property that holds a strongly typed dataset row. 我有一个属性,其中包含一个强类型的数据集行。 I've added an insert and update procedure to my dataset. 我已经向数据集中添加了插入和更新过程。 If I pass the adapter a row that already exists it successfully updates the information. 如果我通过适配器的行已经存在,它将成功更新信息。 However if I create a new row then it won't insert it to the database table. 但是,如果创建新行,则不会将其插入数据库表中。 The exception is never getting thrown, and the int returned is always 0. No new row has been appended. 永远不会引发异常,并且返回的int始终为0。未附加任何新行。

private MyDataset.MyDatasetGetDataRow _row;

private MyDataset.MyDatasetGetDataRow Rowa
{
    get { return _row; }
    set { _row = value; }
}

public void NewOne()
{    
    MyDatasetTableAdapters.MyDatasetGetDataTableAdapter adapter = new MyDatasetTableAdapters.MyDatasetGetDataTableAdapter();
    MyDataset.MyDatasetGetDataDataTable tbl = adapter.GetData(0, 0);
    MyDataset.MyDatasetGetDataRow row = tbl.NewMyDatasetGetDataRow();
    Rowa = row;    
}

public int Save()
{
    try
    {
       int a = -99;
       using (MyDatasetTableAdapters.MyDatasetGetDataTableAdapter adapter = new MyDatasetTableAdapters.MyDatasetGetDataTableAdapter())
       {
           a = adapter.Update(tbl);
       }
       return a;
    }
    catch (Exception ex)
    {
       throw new Exception("Error: It didn't save. (" + ex.Message + ")");
    }

} }

行不属于表,因此数据集不知道该行是新添加的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM