c# - 为什么 IntelliSense 'know' 没有关于我的数据表?

标签 c# visual-studio-2010 datatable intellisense

我创建了一个数据集 (DataSet1.xsd)。然后我创建了一个 TableAdapter (DataTable1TableAdapter) 并添加了一个查询(下图):

dataset

query

当我预览数据时,我看到的正是我所期望的:大量返回的行。

在我的 C# 程序中,在 button1_Click 事件中,我尝试键入以下内容:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MailingList
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.DataTable1TableAdapter.Fill(this.DataSet1.DataTable1);
            foreach (DataRow row in DataTable1.Rows)
            {
                // insert code here to work with the data
            }

        }
    }
}

问题是 IntelliSense 无法识别我的数据表,并在其下方放置了一条波浪形的红线。由于我在设计器屏幕中描述|设计了数据表,难道我不应该可以在我的程序中使用它吗?或者,我是否必须在程序中定义数据表并向其中添加列?

感谢您的帮助!

最佳答案

您需要添加 Dataset to Form1 .

来自 MSDN:

Open the form or component you want to work with. If necessary, switch to Design view of the designer. From the Data tab of the Toolbox, drag a DataSet object onto the designer.

The Choose a Dataset dialog box appears. Select Typed Dataset, and then from the drop-down list, select the dataset you want to use, and then click OK.

The drop-down list is populated with a list of all typed dataset classes in your project.

关于c# - 为什么 IntelliSense 'know' 没有关于我的数据表?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9797528/

相关文章:

c# - .NET 中的 SQL 注入(inject)防护

c# - 在基于 Rx 计数的聚合中,将计数重置为超过最大时间间隔

c# - UWP CalendarView 调整大小后一年发生变化

c++ - 缺少 Visual Studio 2010 Express 64 位属性

visual-studio-2010 - Visual Studio 2010 中构建的输出路径

c# - .NET Core 和 .NET Framework 之间的 CultureInfo 不同

.net - 获取 msbuild 以远程部署干净的应用程序

c# - 有条件地更新数据表中数据的最快方法是什么?

c# - 将数据列添加到数据表

javascript - 无法使用 jquery 删除表中的 tr