Hi, just started playing around with C#, and ran promptly into a problem. So here is -I think - a common newbie question:
Using VS9 and .NET 4.0, I used the designer to construct a solution with a dataset (DataSet1) with DataTables(DataTable1,DataTable2) and a Windows Form (Form1) with Datagridviews for the Tables - no own coding so far. Then I tried to access a Table from Form1, which failed.
DataSet1:
Code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
namespace CSWF {
public partial class DataSet1
{
}
}
Form1:
Code:
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 CSWF
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
//My attempt to deal with the data tables:
try
{
DataTable1.ReadXML("Set1.XML",System.Data.XmlReadMode.Auto);
}
catch (System.IO.FileNotFoundException ex)
{
Console.WriteLine(ex.Message);
}
}
}
How can I enable Form1 to access DataTable1 ?
Thx adv.
Last edited by Wild Thing; November 9th, 2010 at 09:28 AM.
prepare that the light at the end of your tunnel is just a freight train coming your way - metallica
Anyway, may someone tell me what to do on this?
the error I get is
Code:
...: error CS0103: The name 'DataTable1' does not exist in the current context
makes sense, due to the fact that those are different classes. Is there a way to declare them as "friendly class" or "friend assembly" or something like that?
Any hints?
Last edited by Wild Thing; November 9th, 2010 at 02:04 PM.
prepare that the light at the end of your tunnel is just a freight train coming your way - metallica
A class is a template for an object. Unless the class contains static methods that you want to use you need to create an instance of the class within the scope of your form class. You should find a good beginner's tutorial that explains the basics of how classes and objects work.
OK, BigEd, got me on that. I admit I'm with stupid. Got it running now.
I Love this forum; you always get help.
A word to the youngsters:
Books are those paper things that people used before Google. They were helpful, also their search capabilities were very limited. And don't mind if you get a tap on the head or in the neck by the elders time to time, keeps you down to earth and reminds you that you're not immortal - like in the old days.
prepare that the light at the end of your tunnel is just a freight train coming your way - metallica
Bookmarks