Hi all,
I am trying to use a variable that is declared on a separate form.
I have been playing around with it for a few days and eventually discovered I have to make it public, so I changed my code slightly but I'm still having trouble getting it to work. Code below;
The line in the code is the public static one. I have posted a portion of the surrounding code to show it's position within the structure.
CODE
public Form1()
{
InitializeComponent();
}
System.Data.SqlClient.SqlConnection con;
System.Data.SqlClient.SqlDataAdapter da;
public static DataSet ds1 = new DataSet();
int MaxRows = 0;
int inc = 0;
private void Form1_Load(object sender, EventArgs e)
{
And this is the code on my other form that uses this
CODE
public void btnSave_Click(object sender, EventArgs e)
{
DataRow dRow = ds1.Tables["Workers"].NewRow();
dRow[1] = textBox1.Text;
dRow[2] = textBox2.Text;
dRow[3] = textBox3.Text;
ds1.Tables["Workers"].Rows.Add(dRow);
}
The error I'm getting is:
Error 1 The name 'ds1' does not exist in the current context What am I doing wrong? Shouldn't this work?
I just can't seem to figure out what I'm doing wrong
Thanks all,
Premier2k
This post has been edited by Premier2k: 29 Aug, 2008 - 10:39 AM