P
paulquinlan100
Hi
I'm pretty new to C# and have been using a guide from the internet to
populate a DataGridView with data from Access. I've been using the
following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connString = @"Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source=C:\Programme DB\Investment
Programme_be.mdb";
conn = new OleDbConnection(connString);
command = connString.CreateCommand();
DataSet ds = new DataSet();
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = null;
ds = new DataSet();
conn.Open;
command.CommandText = "Select * From NewSites";
adapter = new OleDbDataAdapter(command);
adapter.Fill(ds);
conn.Close();
dataGridView1.DataSource = ds.Tables[0];
}
}
}
However, i get a number of error messages when i compile this,
including:
1. the name 'conn' does not exist in the current context.
2. the name 'command' does not exist in the current context.
3. 'string' does not contain a definition for 'CreateCommand'
4. the name 'ds' does not exist in the current context.
5. Only assignment,call,increment,decrement and new object expressions
can be used as a statement (referring to conn.Open)
6. the name 'adapter' does not exist in the current context.
Im pretty sure i followed the instruction correctly with the only
changes being to point it to my own DB.
Any ideas as to where i'm going wrong?
Thanks a lot.
Paul
I'm pretty new to C# and have been using a guide from the internet to
populate a DataGridView with data from Access. I've been using the
following code:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
using System.Data.OleDb;
namespace WindowsApplication1
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
string connString = @"Provider=Microsoft.JET.OLEDB.4.0;"
+ @"data source=C:\Programme DB\Investment
Programme_be.mdb";
conn = new OleDbConnection(connString);
command = connString.CreateCommand();
DataSet ds = new DataSet();
}
private void button1_Click(object sender, EventArgs e)
{
dataGridView1.DataSource = null;
ds = new DataSet();
conn.Open;
command.CommandText = "Select * From NewSites";
adapter = new OleDbDataAdapter(command);
adapter.Fill(ds);
conn.Close();
dataGridView1.DataSource = ds.Tables[0];
}
}
}
However, i get a number of error messages when i compile this,
including:
1. the name 'conn' does not exist in the current context.
2. the name 'command' does not exist in the current context.
3. 'string' does not contain a definition for 'CreateCommand'
4. the name 'ds' does not exist in the current context.
5. Only assignment,call,increment,decrement and new object expressions
can be used as a statement (referring to conn.Open)
6. the name 'adapter' does not exist in the current context.
Im pretty sure i followed the instruction correctly with the only
changes being to point it to my own DB.
Any ideas as to where i'm going wrong?
Thanks a lot.
Paul