Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem Navigating Data (go to next row)

Status
Not open for further replies.

rs213

Programmer
Jul 16, 2008
1
US
I'm a little stuck. Things are going ok with my programming but I have a little problem. I am trying to navigate to next row in my data table to display data for that row. When I open the database, the first row data is filled in the text box. When I click the next button, it goes to the next (second) row of data. But when I click the next button again, it doesn't go to the next, third row. It just stops at the second row. How can I navigate further? Here's a clip of the code below that I wrote:

private void btnNextPrj_Click(object sender, EventArgs e)
{
//The database connection
SqlCeConnection cnADONetConnection = new SqlCeConnection();
SqlCeDataAdapter daDataAdapter = new SqlCeDataAdapter();
SqlCeCommandBuilder cbCommandBuilder;
DataTable dtProject = new DataTable();
int rowPosition = 0;

// Open the database.
cnADONetConnection.ConnectionString = "Data Source=" + m_strDatabase;

cnADONetConnection.Open();

//Get all data from rsProject Table.
daDataAdapter = new SqlCeDataAdapter("Select * From rsProject", cnADONetConnection);

daDataAdapter.Fill(dtProject);


// If not on the last row, advance one row and show the record.
if (rowPosition < dtProject.Rows.Count -1)
{
rowPosition++;
tbProjectNumber.Text = dtProject.Rows[rowPosition]["ProjectNumber"].ToString();
tbProjectName.Text = dtProject.Rows[rowPosition]["ProjectName"].ToString();
tbProjectAddress.Text = dtProject.Rows[rowPosition]["ProjectAddress"].ToString();
tbProjectCityStateZip.Text = dtProject.Rows[rowPosition]["ProjectCityStateZip"].ToString();
tbArchitect.Text = dtProject.Rows[rowPosition]["Architect"].ToString();
tbArchitectAddress.Text = dtProject.Rows[rowPosition]["ArchitectAddress"].ToString();
tbArchitectCityStateZip.Text = dtProject.Rows[rowPosition]["ArchitectCityStateZip"].ToString();
txtCurrentProject.Text = dtProject.Rows[rowPosition]["ProjectName"].ToString();
txtProjectNumber.Text = dtProject.Rows[rowPosition]["ProjectNumber"].ToString();

}

}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top