Use DataSet for retrieving, updating and inserting data to SQLite

扶醉桌前 提交于 2020-01-13 07:11:30

问题


On visual studio I can create a DataSet of my SQLite database by doing:

1) Connect to sqlite database file and create a table

2) Add new DataSet to my solution (DataSet2.xsd)

3) Drag tables to the designer


Now how can I make use of the objects that visual studio created for me?

for example I am trying to do something like:

        DataSet2.TableTestDataTable t = new DataSet2.TableTestDataTable();
        var objects = t.GetObjectData(..// do not know how to use it

OR

        DataSet2TableAdapters.TableTestTableAdapter t = new DataSet2TableAdapters.TableTestTableAdapter();
        var data = t.GetData(); 

        var q = from a in data
                select a;

        foreach (DataSet2.TableTestRow row in q)
        {
            row.integer = 12345; // change value of column integer               
        }
        t.submitchanges(); // method does note exists

回答1:


    DataSet2TableAdapters.TableTestTableAdapter t = new DataSet2TableAdapters.TableTestTableAdapter();

    DataSet2 ds = new DataSet2();
    t.Fill(ds.TableTest); 

    foreach (DataSet2.TableTestRow row in ds.TableTest.Rows)
    {
        row.integer = 12345; // change value of column integer               
    }

    t.Update(ds2);

Something like that ....




回答2:


Try:

var q = (from a in data
        select a).ToArray();

And instead of t.SubmitChanges(); use t.Update(q);.



来源:https://stackoverflow.com/questions/9215492/use-dataset-for-retrieving-updating-and-inserting-data-to-sqlite

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!