Why doesn't IntelliSense "know" about my datatable?
I have created a dataset (DataSet1.xsd). Then I created a TableAdapter (DataTable1TableAdapter) and added a request (images below):
When I go through the data, I see exactly what I was expecting: many rows returned.
In my C # program, in the button1_Click event, I tried to type the following:
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
}
}
}
}
The problem is IntelliSense doesn't recognize my datatable and puts a red line underneath it. Since I described the data on the designer's screen, shouldn't it be available to me for use in my program? Or do I need to define the data type and add columns to it inside the program?
Thanks for any help!
source to share
You need to add Dataset to Form 1 .
From MSDN:
Open the form or component you want to work with. Switch for projector design if necessary. On the Data tab of the toolbar, drag a DataSet to the designer.
The Select Dataset dialog box appears. Select a typed dataset and then select the dataset you want to use from the drop-down list and then click OK.
The drop-down list displays a list of all typed class datasets in your project.
source to share
The DataTable is part of the DataSet and has no local reference. Change
this.DataTable1TableAdapter.Fill(this.DataSet1.DataTable1);
foreach (DataRow row in DataTable1.Rows)
to
this.DataTable1TableAdapter.Fill(this.DataSet1.DataTable1);
foreach (DataRow row in this.DataSet1.DataTable1.Rows)
source to share