English 中文(简体)
Db4ojects.Db4o.Ext.Database 数据库关闭例外,同时在网视图中更新
原标题:Db4objects.Db4o.Ext.DatabaseClosedException while updating in Gridview

我正在尝试做一个工程, 通过使用 Gridgeview 控制来编辑、更新和删除我的对象, 每次我存储新对象时都会有模糊的例外错误。 事实上我找不到哪里出错 。 我在 DB4o 编程的.NET 中非常新, 我找不到任何可以学习基本内容的好来源, 因此任何引用都会受到完全感谢 。 感谢您事先感谢 。

/ / / 倾卸量

     Db4oService.OpenDB();
     using (var patientdbcontainer = Db4oService.PatientDBContainer)
                    {
                       var list = patientdbcontainer.Query<Patient>(typeof(Patient)).ToList<Patient>();


                       GridView1.DataSource = list;
                       GridView1.DataBind();
                    }

/更新/更新

public void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            //var ID = new Guid((string)e.NewValues["ID"]);

            //    var Name = (string)e.NewValues["Name"];
            //    var IMEI = long.Parse(e.NewValues["IMEI"].ToString());

            Patient updatedPatient = new Patient()
            {
                ID = new Guid((string)e.NewValues["ID"]),
                IMEI =long.Parse(e.NewValues["IMEI"].ToString()),
                Name = (string)e.NewValues["Name"]
            };
            Patient deprecatedPatient;
            using (var patientdbcontainer = Db4oService.PatientDBContainer)
            {

                deprecatedPatient = patientdbcontainer.Query<Patient>(typeof(Patient)).Where<Patient>(n => n.ID == (new Guid((string)e.NewValues["ID"]))).FirstOrDefault<Patient>();
               // deprecatedPatient.Name = ((TextBox)GridView1.Rows[e.RowIndex].Cells[1].Controls[0]).Text;
                deprecatedPatient.ID = updatedPatient.ID;
                deprecatedPatient.Name = updatedPatient.Name;
                patientdbcontainer.Delete(deprecatedPatient);

                patientdbcontainer.Store(updatedPatient);
                patientdbcontainer.Commit();

                GridView1.EditIndex = -1;
                GridView1.DataBind();




            }
问题回答

1) 如果i 低于和您的代码, 也许最好让患者使用 id, 并更新属性和存储更改( 不创建和删除 ) 。

2) You can try http://usefuldb4o.codeplex.com/.

该项目侧重于与 ASP.NET 的合作。 源代码有一个有 CRUD 操作的 ASP. NET 示例( 源代码文件夹 < strong> Examples/ AspNetWebSolutions )

该项目还有一个“Nuget”软件包,其实施实例如下:http://nuget.org/packages/usedful DB4OTOWeb





相关问题
asp.net gridview editindex

Please take a look at this: protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { int index = Convert.ToInt32(e.CommandArgument); if (e.CommandName == "Edit") {...

How do I stop my gridview from caching?

I search for results, click one, it opens in a new window, then edit it, and close the popup. Then I hit search to refresh my gridview, but the changes do not reflect unless I hit F5. It s caching ...

get data from gridview without querying database

I am new at this so please bear with me... I have managed to get the following code to work...so when I click on the "select" link in each row of the gridview, the data is transfered to other label/...

WPF GridView, Display GetType().Name in DisplayMemberBinding

I want include the Type name of each object in my collection from my GridView. I have a collection which has four different types in it that all derive from a base class. Call them, Foo, Bar, Fizz, ...

GridView that toggles percentages of counts

I am using a SqlDataSource that returns a table of raw counts. One of these columns is the "total". I would like to give the user the ability to show these counts as a percentage of total using some ...

热门标签