c# - 在C#中的 ListView 中从access数据库获取数据

标签 c# listview

我想在 C# 的 ListView 中从 Access 数据库获取数据...

这就是我正在使用的:

 private void LstVwBrandNmO_SelectedIndexChanged(object sender, EventArgs e)
    {
        string sql = "select BrandName from Inventory";
        OleDbDataAdapter da = new OleDbDataAdapter(sql, bookConn);
        DataTable dt = new DataTable();
        da.Fill(dt);
        return dt;
    }

下一步做什么?

最佳答案

在获取数据表中的数据后,只需像这样分配Listiew的数据源属性 ListView.DataSource = dt

并使用databind函数将数据源绑定(bind)到列表

ListView.DataBind();

在此之前,请确保您已使用 <%#EVAL#> 定义 Itemtemplate 以绑定(bind)数据源中的值

关于c# - 在C#中的 ListView 中从access数据库获取数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15941104/

相关文章:

c# - 如果 SharePoint 文件夹不存在,则创建该文件夹

c# - Xamarin.Auth - UWP - Windows 拦截的重定向 URL

c# - 为 AlarmManager 设置 Intent

c# - Entity Framework 核心线程安全吗?

Android:如何禁用 ListView?

android - 如何在新的ListView Activity中保存EditText数据

c# - 使用带有 HTTPS 证书的 System.Net.WebClient

java - 将全选行添加到 ListView 中

JQuery Mobile ListView 缩略图对齐

java - asynctask 刷新后尝试访问适配器时出现 nullPointer 异常