将数据从datagridviewsilverlight保存到数据库

本文关键字:数据库 保存 datagridviewsilverlight 数据 | 更新日期: 2023-09-27 17:54:20

我如何保存所有数据从我的DataGrid当我的按钮保存被点击?

这是我的代码,说错误:

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

将数据从datagridviewsilverlight保存到数据库

试试这个

 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
        }
    }

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

    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
您必须记住每一列的类型,以便在每种情况下使用适当的格式。