By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,952 Members | 1,858 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,952 IT Pros & Developers. It's quick & easy.

Navigation through records with NEXT, PREVIOUS, LAST, FIRST buttons

P: n/a
Hi all,

I have a windows form which contains several text boxes. I would like
these text boxes to DataBind to records in an Access.mdb. I have connected
to the Access.mdb using ADO.Net.

When I click on a navigation button, it doesn't matter which navigation
button, the text boxes are not updated to show the new navigated record. I
have included the code I'm using below. I have removed all code I'm sure
does not affect the DataBinding process and I have only left the code for
the MOVE_NEXT button. WHEN THE FULL LISTING IS COMPILED THERE ARE NO
ERRORS.

Any help as to why its not updating correctly will be much appreciated.

Kind regards,
Jon.
-------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace ClientInfo.cs
{

public CurrencyManager currManager;
public DataSet myDSet;
public OleDbDataAdapter myDAdapter;

public frmClientInfo()
{
InitializeComponent();
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=A:\
ClientInfo.mdb";

OleDbConnection myConn = new OleDbConnection(strConn);
myDSet = new DataSet();
myConn.Open();
myDAdapter = new OleDbDataAdapter("SELECT * FROM ClientInfo", myConn);
myDAdapter.Fill(myDSet,"ClientInfo");
Bind();
currManager = (CurrencyManager)this.BindingContext[myDSet.Tables
["ClientInfo"]];

static void Main()
{
Application.Run(new frmClientInfo());
}

public void btnViewNext_Click(object sender, System.EventArgs e)
{
this.currManager.Position += 1;
}
public void Bind()
{
txtName.DataBindings.Add("Text", myDSet, "ClientInfo.Name");
txtAddress1.DataBindings.Add("Text", myDSet, "ClientInfo.Address1");
txtAddress2.DataBindings.Add("Text", myDSet, "ClientInfo.Address2");
txtAddress3.DataBindings.Add("Text", myDSet, "ClientInfo.Address3");
txtAddress4.DataBindings.Add("Text", myDSet, "ClientInfo.Address4");
txtPostcode.DataBindings.Add("Text", myDSet, "ClientInfo.Postcode");

txtPrimaryContactNo.DataBindings.Add("Text", myDSet,
"ClientInfo.PrimaryNo");

txtSecondaryContactNo.DataBindings.Add("Text", myDSet,
"ClientInfo.SecondaryNo");

txtEmail.DataBindings.Add("Text", myDSet, "ClientInfo.Email");
}
}
}
-------------------------------------------------------------------------

--
Message posted via http://www.dotnetmonster.com
Nov 17 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
insted of currManager = (CurrencyManager)this.BindingContext[myDSet.Tables
["ClientInfo"]];
try
currManager = (CurrencyManager)this.BindingContext[myDSet, "ClientInfo"];

"Jon Smith via DotNetMonster.com" wrote:
Hi all,

I have a windows form which contains several text boxes. I would like
these text boxes to DataBind to records in an Access.mdb. I have connected
to the Access.mdb using ADO.Net.

When I click on a navigation button, it doesn't matter which navigation
button, the text boxes are not updated to show the new navigated record. I
have included the code I'm using below. I have removed all code I'm sure
does not affect the DataBinding process and I have only left the code for
the MOVE_NEXT button. WHEN THE FULL LISTING IS COMPILED THERE ARE NO
ERRORS.

Any help as to why its not updating correctly will be much appreciated.

Kind regards,
Jon.
-------------------------------------------------------------------------
using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;
using System.Data;
using System.Data.OleDb;

namespace ClientInfo.cs
{

public CurrencyManager currManager;
public DataSet myDSet;
public OleDbDataAdapter myDAdapter;

public frmClientInfo()
{
InitializeComponent();
string strConn = @"Provider=Microsoft.Jet.OLEDB.4.0;Data Source=A:\
ClientInfo.mdb";

OleDbConnection myConn = new OleDbConnection(strConn);
myDSet = new DataSet();
myConn.Open();
myDAdapter = new OleDbDataAdapter("SELECT * FROM ClientInfo", myConn);
myDAdapter.Fill(myDSet,"ClientInfo");
Bind();
currManager = (CurrencyManager)this.BindingContext[myDSet.Tables
["ClientInfo"]];

static void Main()
{
Application.Run(new frmClientInfo());
}

public void btnViewNext_Click(object sender, System.EventArgs e)
{
this.currManager.Position += 1;
}
public void Bind()
{
txtName.DataBindings.Add("Text", myDSet, "ClientInfo.Name");
txtAddress1.DataBindings.Add("Text", myDSet, "ClientInfo.Address1");
txtAddress2.DataBindings.Add("Text", myDSet, "ClientInfo.Address2");
txtAddress3.DataBindings.Add("Text", myDSet, "ClientInfo.Address3");
txtAddress4.DataBindings.Add("Text", myDSet, "ClientInfo.Address4");
txtPostcode.DataBindings.Add("Text", myDSet, "ClientInfo.Postcode");

txtPrimaryContactNo.DataBindings.Add("Text", myDSet,
"ClientInfo.PrimaryNo");

txtSecondaryContactNo.DataBindings.Add("Text", myDSet,
"ClientInfo.SecondaryNo");

txtEmail.DataBindings.Add("Text", myDSet, "ClientInfo.Email");
}
}
}
-------------------------------------------------------------------------

--
Message posted via http://www.dotnetmonster.com

Nov 17 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.