简体   繁体   English

使用Linq数据库C#显示特定行并在GridView中更新

[英]Display specific rows and update in GridView using Linq database c#

I am new in C# and I want to display specific rows in GridView. 我是C#的新手,我想在GridView中显示特定的行。 I could do this but I could not update it. 我可以这样做,但无法更新。 My code: 我的代码:

 private void bindGridView()
    {
        myContextDataContext context = new myContextDataContext();
        var q2 = from p in context.employees
                 where p.check_is_mngr == 1
                 select p;
        employeeDataGridView.DataSource = q2;
    }

I called bindgridview() in bossAcc_Load function.In my form,I have add_new button and save button. 我在bossAcc_Load函数中调用bindgridview()。在我的表单中,我具有add_new按钮和Save按钮。 This is save button function: 这是保存按钮功能:

private void button5_Click(object sender, EventArgs e)
    {
        this.Validate();
        this.employeeBindingSource.EndEdit();
        this.tableAdapterManager.UpdateAll(this.my_proDataSet);   

    }

But when I click save button,didn't update data.What should I do? 但是,当我单击“保存”按钮时,没有更新数据。该怎么办?

Try this, 尝试这个,

var q2 = from p in context.employees
                 where p.check_is_mngr == 1
                 select p;
employeeDataGridView.DataSource = null;
employeeDataGridView.DataSource = q2 ;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 C# 中的 gridview 上显示数据库中的特定行 - how to show specific rows from database on gridview in C# 使用C#计算其中包含特定字符串变量的mysql数据库行的数量并将其显示为int时出错 - Error using C# to count the number of mysql database rows with specific string varibles in them and display them as int 使用 linq c# 在 datagridview 中显示特定记录 - Display a specific record in the datagridview using linq c# 更新并在gridview中显示(ASP c#) - update and display in gridview (ASP c#) 如何以Gridview linq格式将数据从xml显示到xml C# - How to display data from xml as Gridview linq to xml c# c#linq更新数据库中的所有记录 - c# linq update all records in database 使用C#更新Oracle数据库中多行的最佳方法 - Best way to UPDATE multiple rows in oracle database using C# 使用C#将新添加的datagridview行更新到oledb数据库 - Update newly added rows of datagridview to oledb database using c# 如何在C#中使用LINQ将数据从Gridview或数据库导出到Excel? - How to export data from Gridview or Database to Excel with LINQ in C#? 使用存储过程而不是使用SqlDataSource更新和删除GridView ASP.NET C#中的行 - Update and Delete rows in GridView ASP.NET C# using stored procedure instead of using SqlDataSource
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM