3

I created a dataset (DataSet1.xsd). I then created a TableAdapter (DataTable1TableAdapter) and added a query (images below):

dataset

query

When I preview the data, I see exactly what I was expecting: lots of returned rows.

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 that IntelliSense doesn't recognize my datatable and places a squiggly red line under it. Since I described|desgined the datatable in the designer screen, shouldn't it be available to me to use in my program? Or, do I have to define the datatable and add the columns to it within the program?

Thanks for any help!

Raidri
  • 17,258
  • 9
  • 62
  • 65
Kevin
  • 4,798
  • 19
  • 73
  • 120
  • 1
    Did you add the Dataset to the form? – Raj Ranjhan Mar 21 '12 at 01:46
  • Ah, no, I did not. My form has a button and a multi-line textbox. I had intended to loop through the datatable and write out the results to the textbox. – Kevin Mar 21 '12 at 01:49
  • Anurag, that was the solution. I had to add the dataset, binding source, and tableAdapter to my form. Only after this did the IntelliSense 'know' about my dataset/datatable. If you put this as the answer, I'll mark it. – Kevin Mar 21 '12 at 02:09

2 Answers2

1

You need to add the Dataset to Form1.

From 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.

D Stanley
  • 149,601
  • 11
  • 178
  • 240
Raj Ranjhan
  • 3,869
  • 2
  • 19
  • 29
1

The DataTable is part of the DataSet and does not have a 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)
D Stanley
  • 149,601
  • 11
  • 178
  • 240
  • Thanks! This worked, but only after I followed Anurag's suggestion that I needed to add the dataset (and binding source and table adapter) to my form. – Kevin Mar 21 '12 at 02:17