0

DataGrid单击按钮保存时,如何保存我的所有数据?

这是我的代码并说错误:

string value = (new System.Collections.Generic.Mscorlib_CollectionDebugView<SampleCrudApp.MainPage.GenerateNumber>(grdOrders.ItemsSource)).Items[0].items1;
4

2 回答 2

0

这只是一个示例,因此您可以了解如何获取数据:

    For Each row As DataGridViewRow In dgv.Rows
        For Each cell As DataGridViewCell In row.Cells
            values.Add(cell.Value)
        Next

        sSQL = "INSERT INTO Table (value1,value2,value3) " & _
               "VALUES (" & values(0) & "," & values(1) & "," & values(2) & ")"

        '[...]
    Next

您必须牢记每列的类型,以便在每种情况下使用正确的格式。

于 2013-01-18T06:44:53.847 回答
0

尝试这个

 private void btnSave_Click(object sender, EventArgs e)
    {
        //get data back from the datagrid view
        //assuming my gridview is bound to ObservableCollection<User>
        var users= dataGridView1.DataSource as ObservableCollection<User>;
        foreach (var user in users)
        {
            //perform the save
        }

    }
于 2013-01-18T06:22:48.343 回答