简体   繁体   中英

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.

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 + ")");
    }

}

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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