代码之家  ›  专栏  ›  技术社区  ›  Thomas

亚音速3.0主动记录更新

  •  1
  • Thomas  · 技术社区  · 15 年前

    我可以检索数据库值并插入数据库值,但我无法确定在WHERE语句中update()语法应该是什么。

    环境->ASP.NET,C#

    Settings.ttinclude
    
        const string Namespace = "subsonic_db.Data";
        const string ConnectionStringName = "subsonic_dbConnectionString";
    
        //This is the name of your database and is used in naming
        //the repository. By default we set it to the connection string name
        const string DatabaseName = "subsonic_db";
    

    检索示例

    var product = equipment.SingleOrDefault(x => x.id == 1);
    

    插入示例

       equipment my_equipment = new equipment();
    
        try
        {
            // insert
            my_equipment.parent_id = 0;
            my_equipment.primary_id = 0;
            my_equipment.product_code = product_code.Text;
            my_equipment.product_description = product_description.Text;
            my_equipment.product_type_id = Convert.ToInt32(product_type_id.SelectedItem.Value);
            my_equipment.created_date = DateTime.Now;
            my_equipment.serial_number = serial_number.Text;
    
            my_equipment.Save();
    
        }
        catch (Exception err)
        {
            lblError.Text = err.Message;
        }
    

    编辑:觉得我昨晚太累了,很容易更新。只需使用retrieve函数并对其使用update()。

        var equip = Equipment.SingleOrDefault(x => x.id == 1);
    
        lblGeneral.Text = equip.product_description;
    
        equip.product_description = "Test";
        equip.Update();
    
    1 回复  |  直到 14 年前
        1
  •  0
  •   Thomas    14 年前

    断然的。查看上面的答案。

    推荐文章