Lukasz

Lukasz

  • NA
  • 2
  • 0

object does not exist in the current context

Jul 3 2006 8:23 AM

Please help me with this code. During compilation i got the error: Error 1 The name 'ds' does not exist in the current context : How should I delcare DataSet?
thx
-----------------------------------------------
public
void listBox1_SelectedIndexChanged(object sender, EventArgs e)

{

OleDbDataAdapter dataadapt = new OleDbDataAdapter();

DataSet ds = new DataSet();

StringBuilder sbConn = new StringBuilder();

sbConn.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" + openFileDialog1.FileName);

sbConn.Append(";Extended Properties=");

sbConn.Append(Convert.ToChar(34));

sbConn.Append("Excel 8.0;HDR=Yes;IMEX=2");

sbConn.Append(Convert.ToChar(34));

OleDbConnection cnExcel = new OleDbConnection(sbConn.ToString());

cnExcel.Open();

string exle = "select * from ["+kokon+"]";

dataadapt = new OleDbDataAdapter(exle, sbConn.ToString());

dataadapt.Fill(ds, "symbol");

this.dataGridView1.DataSource = ds;

this.dataGridView1.DataMember = "symbol";

}

public void button2_Click(object sender, EventArgs e)

{

FileStream filestr = new FileStream("mlout.xml",FileMode.OpenOrCreate,FileAccess.Write);

ds.WriteXml(filestr);

}
----------------------------


Answers (1)