我创建了一个数据集 (DataSet1.xsd)。然后我创建了一个 TableAdapter (DataTable1TableAdapter) 并添加了一个查询(下图):
当我预览数据时,我看到的正是我所期望的:大量返回的行。
在我的 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/