Update requires a valid InsertCommand when passed DataRow collection with new rows

前端 未结 3 1743
没有蜡笔的小新
没有蜡笔的小新 2020-12-06 17:11

I am trying to add a new row to my database . Here is my code :

ds1 is my Dataset , da1 is my data adapter

        dRow = ds1.Tables[\"localitati\"]         


        
3条回答
  •  孤城傲影
    2020-12-06 17:55

    Quesion Solved;Your question:

    dRow = ds1.Tables["localitati"].NewRow();
    dRow[1] = aux1.Replace(" ", "").Replace("-", "").ToLower();
    dRow[2] = aux2.ToLower().Replace(" ", "");
    dRow[3] = aux1;
    dRow[4] = e.X;
    dRow[5] = e.Y;
    ds1.Tables["localitati"].Rows.Add(dRow);
    
    da1.Update(ds1, "localitati");
    

    Answer:

    you must use commandBuilder. That is before your update using dataAdapter (or before you creating dataRow) Add the code:

    SqlCommandBuilder cmdb = new SqlCommandBuilder(da);
    

提交回复
热议问题