Click here to Skip to main content
15,921,959 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C#
public void Display_record()
       {
           string query = "Select * from ACCOUNTS where Account_number ='" + comboBox1.SelectedItem + "'";
           //MessageBox.Show(query);
           da1 = new SqlDataAdapter(query, cn);
           dt1 = new DataTable();
           da1.Fill(dt1);
           int i = dt1.Rows.Count-1;
           //for (int i = 0; i <= dt1.Rows.Count - 1; i++)

               comboBox1.Text = (dt1.Rows[i]["Account_number"].ToString());
               txtcustomername.Text = (dt1.Rows[i]["Name"].ToString());
               txtoccupation.Text = (dt1.Rows[i]["Occupation"].ToString());
               txtfathername.Text = (dt1.Rows[i]["Father_name"].ToString());
               txthusbandname.Text = (dt1.Rows[i]["Husband_name"].ToString());
               txtcustomercnic.Text = (dt1.Rows[i]["Customer_CNIC"].ToString());
               txtinitialdeposit.Text = (dt1.Rows[i]["Initial_deposit"].ToString());
               dateTimePicker1.Value = (Convert.ToDateTime(dt1.Rows[i]["Date"]));
               txtpostaladdress.Text = (dt1.Rows[i]["Postal_address"].ToString());
               txtemail.Text = (dt1.Rows[i]["Mail"].ToString());
               txtmobilenumber.Text = (dt1.Rows[i]["Mobile"].ToString());
           }




C#
private void button1_Click(object sender, EventArgs e)
          {

              int i = 0;
              if (i < dt1.Rows.Count - 1)
              {
                  i = i + 1;
                  Display_record();

              }



          }
Posted
Comments
CHill60 4-Dec-12 4:35am    
You haven't included your question
zeshanazam 4-Dec-12 4:47am    
when i click on next button, nothing happens.
bbirajdar 4-Dec-12 4:52am    
what do you expect to happen ?
zeshanazam 4-Dec-12 4:57am    
click on next button and show data next to current in text box fields.

Hi ,

Check this
C#
this.BindingContext[dt].Position += 1;


Best Regards
M.Mitwalli
 
Share this answer
 
I think you suffer from a short term memory loss problem. This is a repost...
You have posted the same question with same code earlier and users have provided you with correct solutions here[^].....

But you posted the same question again. I can guarantee that the solutions are correct. Just check if the database has the data for the selected criteria and learn some basics of ado.net from here[^]
Debug the code line by line and check if every object is assigned its expected value? Check the exception if any..
 
Share this answer
 
v4
Your code should be like this.
C#
int recordindex =0;

string query = "Select * from ACCOUNTS where Account_number ='" + comboBox1.SelectedItem + "'";
//MessageBox.Show(query);
da1 = new SqlDataAdapter(query, cn);
dt1 = new DataTable();
da1.Fill(dt1);

    

public void Display_record(int i)
{
    
               comboBox1.Text = (dt1.Rows[i]["Account_number"].ToString());
               txtcustomername.Text = (dt1.Rows[i]["Name"].ToString());
               txtoccupation.Text = (dt1.Rows[i]["Occupation"].ToString());
               txtfathername.Text = (dt1.Rows[i]["Father_name"].ToString());
               txthusbandname.Text = (dt1.Rows[i]["Husband_name"].ToString());
               txtcustomercnic.Text = (dt1.Rows[i]["Customer_CNIC"].ToString());
               txtinitialdeposit.Text = (dt1.Rows[i]["Initial_deposit"].ToString());
               dateTimePicker1.Value = (Convert.ToDateTime(dt1.Rows[i]["Date"]));
               txtpostaladdress.Text = (dt1.Rows[i]["Postal_address"].ToString());
               txtemail.Text = (dt1.Rows[i]["Mail"].ToString());
               txtmobilenumber.Text = (dt1.Rows[i]["Mobile"].ToString());
}



private void button1_Click(object sender, EventArgs e)
{
              
              if (recordindex >= dt1.Rows.Count-1)
              {

                  //show end of record message.               
               }
              elseif (recordindex == 0)
              {
                 Display_record(recordindex);               
              }
              else
              {
                  recordindex++;
                  Display_record(recordindex);
               }

 }   

All The Best!!!!!
 
Share this answer
 
v2
Comments
Simon_Whale 4-Dec-12 6:21am    
you should seriously look into parameterised queries.

http://www.functionx.com/aspnet_csharp/articles/parameterized.htm
w.pravin 4-Dec-12 6:45am    
thank you Simon, your suggestions are welcome.
Here is a skeleton of an approach that I would use. http://www.functionx.com/aspnet_csharp/articles/parameterized.htm[^] is a place to start for paramterised queries.

C#
//global variables
int RecordPosition = 0;
int MaxRecords = 0;
DataTable records = null;

public void GetData()
{
  string Query = "your select statement";
  //BUT MAKE SURE YOU USE PARAMETERISED QUERY if you have a where clause that
  //is dependant on your forms values

  da1 = new SqlDataAdapter(query, cn);
  records = new DataTable();
  da1.Fill(records);

  MaxRecords = records.count - 1;

  DisplayRecord(RecordPosition);
}

public void DisplayRecord(int Position)
{
  //Do your displaying HERE

  //increment the record pointer
  RecordPosition += 1;
}

public void ButtonClicked(object sender, EventArgs e)
{
   //Test that the RecordPosition isn't Greater than the MaxRecords
   //if it passes that test then
   DisplayRecord(RecordPosition);
}
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900