-
November 9th, 2010, 10:23 AM
#1
[RESOLVED] Accessing DataTables from Windows Form
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 10:28 AM.
prepare that the light at the end of your tunnel is just a freight train coming your way - metallica
-
November 9th, 2010, 11:05 AM
#2
Re: Accessing DataTables from Windows Form
Download the 101 Samples. They have examples for VB.Net as well as C# in VS2008 or VS2010. Get the one that you like
-
November 9th, 2010, 02:51 PM
#3
Re: Accessing DataTables from Windows Form
@dglienna: thanks. Just a small correction: the link is VB, C# is http://code.msdn.microsoft.com/cs2008samples
I will look thru that; examples are always helpful.
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 03:04 PM.
prepare that the light at the end of your tunnel is just a freight train coming your way - metallica
-
November 9th, 2010, 02:56 PM
#4
Re: Accessing DataTables from Windows Form
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.
-
November 9th, 2010, 04:17 PM
#5
Re: Accessing DataTables from Windows Form
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|