执行 SQL 从 LightSwitch C# 按钮中删除

Execute SQL Delete from LightSwitch C# button

希望这里是直截了当的..

我有一个 Visual Studio LightSwitch HTML 客户端应用程序,它使用两个视图作为其数据源。

Within the application I want to have a Delete button which executes a SQL query, deleting the record from a table which has a matching ID to the one currently selected within the app.

我发现这个很方便 MSDN article,它看起来很简单,但是当我尝试实现它时,我收到了智能感知错误。我是 C# 的完全新手,所以我的武器库中没有太多可以用来解决这个问题的东西。

MSDC has this quote

4.In the Screen Designer, open the shortcut menu for the button node, and then choose Edit Execute Code.

5.Add code that resembles the following example:

partial void UpdateEmployeeInfo_Execute()
{
    DataWorkspace dataWorkspace = new DataWorkspace();
    Employee employee = this.Employees.SelectedItem;

    UpdatePersonalInfoOperation operation = 
        dataWorkspace.ApplicationData.UpdateEmployeePersonalInfoOperations.AddNew();
    operation.EmployeeID = employee.EmployeeID;
    operation.NationalIDNumber = employee.NationalIDNumber;
    operation.BirthDate = employee.BirthDate;
    operation.MaritalStatus = employee.MaritalStatus;
    operation.Gender = employee.Gender;

    dataWorkspace.ApplicationData.SaveChanges();
}

我的困惑是,当您选择编辑执行代码时,它会自动生成函数标签:

myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {
    // Write code here.

};

Should the MSDN code go within that function, or am I replacing the default entirely?

在没有部分无效声明的情况下将代码插入到自动生成的标签中时,我在数据工作空间、员工和操作上收到错误提示 Expected';' 如果我将整个未更改的 MSDN 代码粘贴在标签中,或者在没有自动生成标签的情况下执行 MSDN 标签,我也会在 void

一词上遇到同样的错误

感谢所有帮助。我什至还没有开始构建我的查询并建立连接..一次做一件事

Lightswitch HTML 使用 JavaScript 作为隐藏代码,而不是 C#。典型的 LS 删除命令示例:

screen.Items.deleteSelected();

你的情况:

myapp.ViewRecordDetails.DeleteRecord_execute = function (screen) {
    // Write code here.
    screen.Items.deleteSelected();
};

我在这里回答过类似的问题: