Simple Binding

  • Thread starter Thread starter Tony Johansson
  • Start date Start date
T

Tony Johansson

Hello!

Here is a simple program where I try to bind myCount which is the number of
rows in table Customers
to a Label's text control named myLabel.
When I run this code I get run time error on the last row saying
"Objektreference has not been set to an instance of the object"

Can somebody tell be what I have missed here ?

public Form()
{
SqlDataAdapter myAdapter;
DataSet myDataSet;
BindingSource myBinding;

string connectionString = @"Integrated Security=true;" +
"Initial Catalog=Northwind;" +
"Data Source=hempc\\SQLExpress";

myAdapter = new SqlDataAdapter("select count(*) as myCount from
customers", connectionString);
myAdapter.TableMappings.Add("Customers", "Customers");
myDataSet = new DataSet();
myAdapter.Fill(myDataSet, "Customers");
myBinding = new BindingSource(myDataSet, "Customers");
this.myLabel.DataBindings.Add("Text", myBinding, "myCount");
}

//Tony
 
Back
Top